home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / standards / posix / 1003.2 / all < prev    next >
Encoding:
Text File  |  1993-07-15  |  2.7 MB  |  78,013 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1.          IEEE P1003.2 Draft 11.2 - September 1991
  2.  
  3.  
  4.             Copyright (c) 1991 by the
  5.      Institute of Electrical and Electronics Engineers, Inc.
  6.                345 East 47th Street
  7.              New York, NY 10017, USA
  8.            All rights reserved as an unpublished work.
  9.  
  10.        This is an unapproved and unpublished IEEE Standards Draft,
  11.        subject to change.  The publication, distribution, or
  12.        copying of this draft, as well as all derivative    works based
  13.        on this draft, is expressly prohibited except as    set forth
  14.        below.
  15.  
  16.        Permission is hereby granted for    IEEE Standards Committee
  17.        participants to reproduce this document for purposes of IEEE
  18.        standardization activities only,    and subject to the
  19.        restrictions contained herein.
  20.  
  21.        Permission is hereby also granted for member bodies and
  22.        technical committees of ISO and IEC to reproduce    this
  23.        document    for purposes of    developing a national position,
  24.        subject to the restrictions contained herein.
  25.  
  26.        Permission is hereby also granted to the    preceding entities
  27.        to make limited copies of this document in an electronic
  28.        form only for the stated    activities.
  29.  
  30.        The following restrictions apply    to reproducing or
  31.        transmitting the    document in any    form:  1) all copies or
  32.        portions    thereof    must identify the document's IEEE project
  33.        number and draft    number,    and must be accompanied    by this
  34.        entire notice in    a prominent location; 2) no portion of this
  35.        document    may be redistributed in    any modified or    abridged
  36.        form without the    prior approval of the IEEE Standards
  37.        Department.
  38.  
  39.        Other entities seeking permission to reproduce this
  40.        document, or any    portion    thereof, for standardization or
  41.        other activities, must contact the IEEE Standards Department
  42.        for the appropriate license.
  43.  
  44.        Use of information contained in this unapproved draft is    at
  45.        your own    risk.
  46.  
  47.         IEEE Standards Department
  48.         Copyright and Permissions
  49.         445    Hoes Lane, P.O.    Box 1331
  50.         Piscataway,    NJ 08855-1331, USA
  51.         +1 (908) 562-3800
  52.         +1 (908) 562-1571 [FAX]
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.                                                         P1003.2 Draft 11.2
  73.                                                        ISO/IEC CD 9945-2.2
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.                              STANDARDS PROJECT
  83.  
  84.                Draft Standard for Information Technology --
  85.                 Portable Operating System Interface (POSIX)
  86.                                   Part 2:
  87.                             Shell and Utilities
  88.  
  89.  
  90.                                   Sponsor
  91.                  Technical Committee on Operating Systems
  92.                        and Application Environments
  93.                                   of the
  94.                            IEEE Computer Society
  95.  
  96.                       Work Item Number: JTC 1.22.21.2
  97.  
  98.  
  99.  Abstract:  ISO/IEC 9945-2: 199x (IEEE Std 1003.2-199x)  is  part  of  the
  100.  POSIX  series  of  standards for applications and user interfaces to open
  101.  systems.  It defines  the  applications  interface  to  a  shell  command
  102.  language and a set of utility programs for complex data manipulation.
  103.  
  104.  Keywords:  API, application portability, data processing,  open  systems,
  105.  operating system, portable application, POSIX, shell and utilities
  106.  
  107.  
  108.                               P1003.2 / D11.2
  109.                               September 1991
  110.  
  111.  
  112.                          Copyright (c) 1991 by the
  113.           Institute of Electrical and Electronics Engineers, Inc.
  114.                            345 East 47th Street
  115.                           New York, NY 10017, USA
  116.                            All rights reserved.
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  _T_h_i_s _i_s _a_n _u_n_a_p_p_r_o_v_e_d _I_E_E_E _S_t_a_n_d_a_r_d_s _D_r_a_f_t, _s_u_b_j_e_c_t _t_o _c_h_a_n_g_e. _P_e_r_m_i_s_s_i_o_n
  170.  _i_s _h_e_r_e_b_y _g_r_a_n_t_e_d _f_o_r _I_E_E_E _S_t_a_n_d_a_r_d_s _C_o_m_m_i_t_t_e_e _p_a_r_t_i_c_i_p_a_n_t_s _t_o _r_e_p_r_o_d_u_c_e
  171.  _t_h_i_s _d_o_c_u_m_e_n_t _f_o_r _p_u_r_p_o_s_e_s _o_f _I_E_E_E _s_t_a_n_d_a_r_d_i_z_a_t_i_o_n _a_c_t_i_v_i_t_i_e_s. _P_e_r_m_i_s_s_i_o_n
  172.  _i_s _a_l_s_o _g_r_a_n_t_e_d _f_o_r _m_e_m_b_e_r _b_o_d_i_e_s _a_n_d _t_e_c_h_n_i_c_a_l _c_o_m_m_i_t_t_e_e_s _o_f _I_S_O _a_n_d _I_E_C
  173.  _t_o _r_e_p_r_o_d_u_c_e _t_h_i_s _d_o_c_u_m_e_n_t _f_o_r _p_u_r_p_o_s_e_s _o_f _d_e_v_e_l_o_p_i_n_g _a _n_a_t_i_o_n_a_l _p_o_s_i_t_i_o_n.
  174.      _O_t_h_e_r _e_n_t_i_t_i_e_s _s_e_e_k_i_n_g _p_e_r_m_i_s_s_i_o_n _t_o _r_e_p_r_o_d_u_c_e _t_h_i_s _d_o_c_u_m_e_n_t _f_o_r
  175.    _s_t_a_n_d_a_r_d_i_z_a_t_i_o_n _o_r _o_t_h_e_r _a_c_t_i_v_i_t_i_e_s, _o_r _t_o _r_e_p_r_o_d_u_c_e _p_o_r_t_i_o_n_s _o_f _t_h_i_s
  176.      _d_o_c_u_m_e_n_t _f_o_r _t_h_e_s_e _o_r _o_t_h_e_r _u_s_e_s, _m_u_s_t _c_o_n_t_a_c_t _t_h_e _I_E_E_E _S_t_a_n_d_a_r_d_s
  177.  _D_e_p_a_r_t_m_e_n_t _f_o_r _t_h_e _a_p_p_r_o_p_r_i_a_t_e _l_i_c_e_n_s_e.  _U_s_e _o_f _i_n_f_o_r_m_a_t_i_o_n _c_o_n_t_a_i_n_e_d _i_n
  178.                 _t_h_i_s _u_n_a_p_p_r_o_v_e_d _d_r_a_f_t _i_s _a_t _y_o_u_r _o_w_n _r_i_s_k.
  179.  
  180.  IEEE Standards Department
  181.  Copyright and Permissions
  182.  445 Hoes Lane, P.O. Box 1331
  183.  Piscataway, NJ 08855-1331, USA
  184.  +1 (908) 562-3800
  185.  +1 (908) 562-1571 [FAX]
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  _S_e_p_t_e_m_b_e_r _1_9_9_1                                                   _S_H _X_X_X_X_X
  205.  
  206.  BEGIN_RATIONALE
  207.  
  208.  _E_d_i_t_o_r'_s _N_o_t_e_s
  209.  
  210.  The IEEE ballot for Draft 11.2 is due at the  IEEE  Standards  Office  on  2
  211.  _2222_1111 _OOOO_cccc_tttt_oooo_bbbb_eeee_rrrr _1111_9999_9999_1111.   You are also asked to e-mail any balloting comments to  2
  212.  me:  hlj@posix.com.  Please read the balloting instructions in Annex G.    2
  213.  
  214.  This  document  is  also  registered  as  ISO/IEC   CD   9945-2.2.    The  2
  215.  international  balloting  period  is  unrelated  to  the  IEEE balloting.  2
  216.  Member bodies, please  consult  any  accompanying  materials  from  SC22.  2
  217.  Also, please read the remainder of these Editor Notes to see explanations  2
  218.  of  stylistic  differences  between  a  draft  and  the  final   standard  2
  219.  (copyright notices, inline rationale, etc.).                               2
  220.  
  221.  The IEEE balloting will be on hiatus during the  international  balloting  2
  222.  period,  which  is  probably  scheduled  to complete at the May 1992 WG15  2
  223.  meeting.  This is in accordance with the WG15 Synchronization Plan, which  2
  224.  calls for coordinated balloting to result in the approval of an IEEE/ANSI  2
  225.  standard that is identical to the ISO/IEC  Draft  International  Standard  2
  226.  (DIS).   There  will be a final recirculation of a full draft (12) to the  2
  227.  IEEE balloting group before it is sent to the Standards Board.             2
  228.  
  229.  This section will not appear in the  final  document.   It  is  used  for  2
  230.  editorial  comments  concerning  this  draft.   Draft  11.2  is the fifth  2
  231.  recirculation of the balloting process that began in December  1988  with  2
  232.  Draft 8.  Please consult Annex G and the cover letter for the ballot that
  233.  accompanied this draft  for  information  on  how  the  recirculation  is
  234.  accomplished.
  235.  
  236.  This draft uses small numbers in the right margin in lieu of change bars.  2
  237.  ``2''  denotes  changes  from  Draft  11.1  to Draft 11.2.  ``1'' denotes  2
  238.  changes from Draft 11 to Draft 11.1.  All diff-marks prior to Draft  11.1  1
  239.  have been removed.  Trivial informative (i.e., non-normative) changes and
  240.  purely editorial changes such as grammar, spelling, or  cross  references
  241.  are not diff-marked.
  242.  
  243.  There are two versions of Draft 11.2 in circulation.   The  full  printed  2
  244.  version  was  sent for SC22 balloting and is also available from the IEEE  2
  245.  for a duplication fee [call (800) 678-IEEE or  +1 (908) 981-1393  outside  2
  246.  the  US].  The version sent to the IEEE balloting group consists (mostly)  1
  247.  of pages containing normative changes.  This was done to focus  balloting  1
  248.  group  attention  on  the  changes being balloted and to reduce costs and  1
  249.  administrative time.  The changes-only version contains a few handwritten  1
  250.  pointers  in  the  margins to show context where it would not be obvious;  1
  251.  numbers near the normal page numbers show what the corresponding Draft 11  1
  252.  page number would be.                                                      1
  253.  
  254.  
  255.                Copyright c 1991 IEEE.  All rights reserved.
  256.       This is an unapproved IEEE Standards Draft, subject to change.
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  The following minor global changes have been made without diff-marks:
  271.  
  272.      - Instances  of  the  verbs   ``print,''   ``report,''   ``display,''
  273.        ``issue,'' and ``list'' are being changed to ``write'' as part of a
  274.        general cleanup related to the UPE, where ``write'' and ``display''
  275.        have  precise  meanings.   This  is probably not completed and will
  276.        continue  throughout  ballot  resolution  and  the  final   editing
  277.        process.
  278.  
  279.  ISO and IEEE have tightened up the requirements for the use of ``shall.''
  280.  We  have  been directed that all sentences that are currently declarative
  281.  must be changed to use the ``shall'' form if  they  pose  a  requirement:
  282.  ``The  status  is  zero''  -> ``The status shall be zero.''  One specific
  283.  instance of  this  was  changing  ``The  following  options/operands  are
  284.  available'' to ``The following options/operands shall be supported by the
  285.  implementation.''   Another:   ``The  foo  utility  follows  the  utility
  286.  argument syntax standard described in 2.11.2'' to ``The foo utility shall
  287.  conform to the utility argument syntax guidelines described in  2.10.2.''
  288.  It  is  a  tedious  process to do all these translations and they are not
  289.  complete.  They  will  completed  on  a  draft-by-draft  basis.   In  the
  290.  meantime,  please  assume  that  all  declarative  sentences  mean to use
  291.  ``shall''  and  treat  them  as  either  implementation  or   application
  292.  requirements   unless  they  specifically  say  ``may,''  ``should,''  or
  293.  ``can.''
  294.  
  295.  The rationale text for all the sections has been temporarily  moved  from
  296.  Annex  E  and  interspersed with the appropriate sections.  The rationale
  297.  sections are identified with the phrase ``(_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t  _a  _p_a_r_t
  298.  _o_f  _P_1_0_0_3._2)''  in  the  heading.   This colocation of rationale with its
  299.  accompanying text was  done  to  encourage  the  Technical  Reviewers  to
  300.  maintain  the  rationale  text,  as  well  as provide explanations to the
  301.  reviewers and balloters.  Not all of the Rationale sections have contents
  302.  as  of  this draft.  The empty sections may be partially distracting, but
  303.  we feel it is imperative to keep them there to  encourage  the  Technical
  304.  Reviewers to provide rationale as needed.
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.                Copyright c 1991 IEEE.  All rights reserved.
  322.       This is an unapproved IEEE Standards Draft, subject to change.
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  Please report typographical errors to:
  337.  
  338.        Hal Jespersen
  339.        POSIX Software Group
  340.        447 Lakeview Way
  341.        Redwood City, CA 94062
  342.        +1 (415) 364-3410
  343.        FAX: +1 (415) 364-4498
  344.        Email: hlj@Posix.COM
  345.  
  346.  (_E_l_e_c_t_r_o_n_i_c _m_a_i_l _i_s _p_r_e_f_e_r_r_e_d.)
  347.  
  348.  The copying and distribution of IEEE balloting drafts is accomplished by
  349.  the Standards Office.  To report problems with reproduction of your copy,  2
  350.  contact:                                                                   2
  351.  
  352.        Anna Kaczmarek                                                       2
  353.        IEEE Standards Office
  354.        P.O. Box 1331
  355.        445 Hoes Lane
  356.        Piscataway, NJ 08855-1331
  357.  
  358.        +1 (908) 562-3811                                                    2
  359.        FAX: +1 (908) 562-1571
  360.  
  361.  Additional copies of this draft are available for a duplication and        2
  362.  mailing fee.  Contact:                                                     2
  363.  
  364.        IEEE Publications                                                    2
  365.        1 (800) 678-IEEE                                                     2
  366.        +1 (908) 981-1393 [outside US]                                       2
  367.  
  368.  This draft is available in various electronic forms to assist the review   2
  369.  process.  Our thanks to Andrew Hume of AT&T Bell Laboratories for          2
  370.  providing online access facilities.  Note that this is a limited           2
  371.  experiment in providing online access; future ballots may provide other    2
  372.  forms, such as diskettes or a bulletin board arrangement, but the          2
  373.  instructions shown here are the only methods currently available.  Please  2
  374.  also observe the additional copyright restrictions that are described in   2
  375.  the online files.                                                          2
  376.  
  377.  Assuming you have access to the Internet, the scenario is approximately    2
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.                Copyright c 1991 IEEE.  All rights reserved.
  388.       This is an unapproved IEEE Standards Draft, subject to change.
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.        ftp research.att.com # research's IP address is 192.20.225.2         2
  403.        <login as netlib; password is your email address>                    2
  404.        cd posix/p1003.2/d11.2                                               2
  405.        get toc index                                                        2
  406.        binary                                                               2
  407.        get p11-20.Z                                                         2
  408.  
  409.  The draft is available in several forms.  The table of contents can be     2
  410.  found in toc, pages containing a particular section are stored under the   2
  411.  section number, sets of pages are stored in files with names of the form   2
  412.  p_n-_m, and the entire draft is stored in all.  By default, files are        2
  413.  ASCII.  A .ps suffix indicates PostScript.  A .Z suffix indicates a        2
  414.  compress'_e_d file.  The file index contains a general description of the    2
  415.  files available.                                                           2
  416.  
  417.  These files are also available via electronic mail by sending a message    2
  418.  like                                                                       2
  419.  
  420.        send 3.4 3.5 9.2 from posix/p1003.2/d11.2                            2
  421.  
  422.  to netlib@research.att.com.  If you use email, you should _n_o_t ask for the  2
  423.  compressed version.  For a more complete introduction to this form of      2
  424.  _n_e_t_l_i_b, send the message                                                   2
  425.  
  426.        send help                                                            2
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.                Copyright c 1991 IEEE.  All rights reserved.
  454.       This is an unapproved IEEE Standards Draft, subject to change.
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  _P_O_S_I_X._2 _C_h_a_n_g_e _H_i_s_t_o_r_y
  469.  
  470.  This section is provided to track major changes between drafts.  Since it
  471.  was first added in Draft 11, earlier entries omit some degree of detail.
  472.  
  473.     Draft 11.2  [September 1991] Sixth IEEE ballot (fifth recirculation;    2
  474.                 only changed pages distributed).  Second ISO/IEC CD 9945-2  2
  475.                 registration (full draft distributed).                      2
  476.  
  477.                  - Equivalence classes as starting/ending points of         2
  478.                    regular expression bracket expression range expression   2
  479.                    have been made unspecified.                              2
  480.  
  481.                  - The LC_COLLATE substitute keyword has been deleted.      2
  482.  
  483.                  - cksum (4.9):  Modifications to the algorithm.            2
  484.  
  485.                  - cp (4.13):  Restoration of the                           2
  486.  
  487.                  - stty (4.59):  Addition of the tostop operand.            2
  488.  
  489.                  - lex (A.2):  Further clarification of ERE differences.    2
  490.  
  491.                  - Miscellaneous clarifications to various utilities.       2
  492.  
  493.     Draft 11.1  [June 1991] Fifth IEEE ballot (fourth recirculation; only   1
  494.                 changed pages distributed).                                 1
  495.  
  496.                  - Modification of the definition of _b_y_t_e and               1
  497.                    clarifications of octal/hexadecimal byte                 1
  498.                    representations throughout the utilities.                1
  499.  
  500.                  - Clarifications to the locale definition source file      1
  501.                    description in 2.5; addition of a yacc grammar.          1
  502.  
  503.                  - Removal of pax -e character translation option.          1
  504.  
  505.                  - Miscellaneous clarifications to various utilities.       1
  506.  
  507.                  - Reconciliation of feature test macros and headers in     1
  508.                    Annex B with POSIX.1.                                    1
  509.  
  510.     Draft 11    [February 1991] Fourth IEEE ballot (third recirculation).
  511.  
  512.                  - Changes in 2.3 to the treatment of regular built-ins in
  513.                    regards to their _e_x_e_c-able versions.
  514.  
  515.                  - Changes to 2.4 (character names and charmap syntax) and
  516.                    2.5 (localedef input format) as a result of
  517.  
  518.  
  519.                Copyright c 1991 IEEE.  All rights reserved.
  520.       This is an unapproved IEEE Standards Draft, subject to change.
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.                    international balloting.  Addition of the
  535.                    {POSIX2_LOCALEDEF} symbol.
  536.  
  537.                  - Changes to the shell quoting rules, arithmetic
  538.                    expression syntax, command search order, error
  539.                    descriptions, and exportable functions.
  540.  
  541.                  - Movement of the command utility from special built-in
  542.                    status to be a utility in Section 4.
  543.  
  544.                  - cp (4.13):  Significant clarifications and interface
  545.                    changes.
  546.  
  547.                  - date (4.15):  Added field descriptor modifiers to
  548.                    handle alternate calendar forms when supported by the
  549.                    locale and implementation.
  550.  
  551.                  - pax (4.48):  Significant interface changes, including
  552.                    international character set translations.
  553.  
  554.                  - test (4.62):  Deprecated some functionality due to
  555.                    inconsistent behavior in existing implementations that
  556.                    cause portability problems in existing applications.
  557.  
  558.                  - make (6.2):  Addition of the .POSIX special target,
  559.                    return of some rules to strict existing practice.
  560.  
  561.                  - Miscellaneous clarifications to various utilities.
  562.  
  563.                  - The FORTRAN section now has two options associated with
  564.                    it:  Development Utilities (fort77) and Runtime
  565.                    Utilities (asa).
  566.  
  567.                  - Addition of full example profiles and charmaps from
  568.                    Denmark in Annex F.
  569.  
  570.     Draft 10    [July 1990] Third IEEE ballot (second recirculation).
  571.  
  572.                  - This draft primarily has been one of clarification and
  573.                    amplification.  In resolving ballot objections, large
  574.                    portions of the draft have been rewritten, affecting
  575.                    all sections, but comparatively few changes in
  576.                    [intended] functionality have occurred.
  577.  
  578.                  - New shell command language features (see Section 3):
  579.  
  580.                  - Utility name changes:
  581.  
  582.                                      Draft 9   Draft 10
  583.  
  584.  
  585.                Copyright c 1991 IEEE.  All rights reserved.
  586.       This is an unapproved IEEE Standards Draft, subject to change.
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.                                      _______   ________
  601.                                      create    pathchk
  602.                                      hexdump   od
  603.                                      sendto    mailx
  604.  
  605.                  - A few of the utilities and global sections now have a
  606.                    more formal description, using a yacc-like grammar.
  607.  
  608.                  - Considerably more detail has been added to the
  609.                    internationalization features of the standard:  global
  610.                    changes to clauses 2.4 and 2.5; new detail to the LC_*
  611.                    variables in each utility section; specification of
  612.                    LC_MESSAGES (replacing LC_RESPONSE).
  613.  
  614.                  - Due to some ISO requirements, Sections 1 and 2 have
  615.                    been reorganized yet again, causing many cross
  616.                    reference number changes.  The Related Standards annex
  617.                    has been turned into simply a Bibliography.  The Non-
  618.                    Specified Language Compilers annex has been replaced by
  619.                    a Sample National Profile annex.
  620.  
  621.     Draft 9     [August 1989] Second IEEE ballot (first recirculation).
  622.                 Also registered as ISO/IEC CD 9945-2.1.  A few minor
  623.                 corrections to some sections.  :-)
  624.  
  625.     Draft 8     [December 1988] First IEEE ballot.  Also submitted to
  626.                 ISO/IEC JTC 1/SC22 for review and comment.
  627.  
  628.     Draft 7     [September 1988] ``Mock ballot'' conducted by working
  629.                 group members only.
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.                Copyright c 1991 IEEE.  All rights reserved.
  652.       This is an unapproved IEEE Standards Draft, subject to change.
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  _P_O_S_I_X._2 _T_e_c_h_n_i_c_a_l _R_e_v_i_e_w_e_r_s
  667.  
  668.  The individuals denoted in Table i are the Technical Reviewers for this
  669.  draft.  During balloting they are the subject matter experts who
  670.  coordinate the resolution process for specific sections, as shown.
  671.  
  672.                    Table i - POSIX.2 Technical Reviewers
  673.  
  674.  __________________________________________________________________________________________________________________________________________________
  675.     Section                   Description                    Reviewer
  676.     ___________________________________________________________________
  677.  
  678.        1       _G_e_n_e_r_a_l                                     Jespersen
  679.     2.4,2.5    _D_e_f_i_n_i_t_i_o_n_s (_L_o_c_a_l_e_s)                       Leijonhufvud     1
  680.     2 (rest)   _D_e_f_i_n_i_t_i_o_n_s (_V_a_r_i_o_u_s)                       Jespersen
  681.        3       _C_o_m_m_a_n_d _L_a_n_g_u_a_g_e                            Jespersen
  682.        4       _E_x_e_c_u_t_i_o_n _E_n_v_i_r_o_n_m_e_n_t _U_t_i_l_i_t_i_e_s:  _c_p, rm    Bostic           22
  683.        4       _E_x_e_c_u_t_i_o_n _E_n_v_i_r_o_n_m_e_n_t _U_t_i_l_i_t_i_e_s:  (_t_h_e      Jespersen        22
  684.                _r_e_s_t)                                                        2
  685.        6       _S_o_f_t_w_a_r_e _D_e_v_e_l_o_p_m_e_n_t _U_t_i_l_i_t_i_e_s              Jespersen
  686.        7       _L_a_n_g_u_a_g_e-_I_n_d_e_p_e_n_d_e_n_t _B_i_n_d_i_n_g_s               Jespersen        2
  687.        A       _C _D_e_v_e_l_o_p_m_e_n_t _U_t_i_l_i_t_i_e_s                     Jespersen
  688.        B       _C _B_i_n_d_i_n_g_s                                  Jespersen        2
  689.        C       _F_O_R_T_R_A_N _D_e_v_e_l_o_p_m_e_n_t _a_n_d _R_u_n_t_i_m_e _U_t_i_l_i_t_i_e_s   Jespersen
  690.       D-G      _V_a_r_i_o_u_s                                     Jespersen
  691.  __________________________________________________________________________________________________________________________________________________
  692.  
  693.  
  694.  Also, our special thanks to Donn Terry for writing or improving all the
  695.  yacc-based grammars used in Draft 10.
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.                Copyright c 1991 IEEE.  All rights reserved.
  718.       This is an unapproved IEEE Standards Draft, subject to change.
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  _P_O_S_I_X._2 _P_r_o_p_o_s_e_d _S_c_h_e_d_u_l_e
  733.  
  734.  This section will not appear in the final document.  It is used to
  735.  provide editorial notes regarding the proposed POSIX.2 schedule.  In the
  736.  schedule, the UPE stands for ``User Portability Extension.''
  737.  
  738.  
  739.    _____________________________________________________________________
  740.    |        Date          |     Milestone (End of Meeting)      | Draft |
  741.    _|_______________________|______________________________________|_______|
  742.    |Sep 7-11, 1987        | Utility format frozen;              |   3   |
  743.    |Nashua, NH            | 10% of utilities described.         |       |
  744.    _|_______________________|______________________________________|_______|
  745.    |Dec 7-14, 87          | 50% of utilities described;         |   4   |
  746.    |San Diego, CA         | shell update; substantial           |       |
  747.    _|_______________________|_p_r_o_g_r_e_s_s__i_n__S_e_c_t_i_o_n_s__2_,__3_,__4_,__8_.______|_______|
  748.    |Mar 14-18, 1988       | Utility selection frozen;           |   5   |
  749.    |Washington, DC        | 75% described.                      |       |
  750.    _|_______________________|______________________________________|_______|
  751.    |Jul 11-15, 1988       | 100% utilities described;           |   6   |
  752.    |Denver, CO            | functional freeze; produce ``mock   |       |
  753.    _|_______________________|_b_a_l_l_o_t_'_'__a_n_d__P_O_S_I_X__F_I_P_S__d_r_a_f_t__7_______|_______|
  754.    |[Sep-Oct 1988]        | [Mock ballot]                       |   7   |
  755.    _|_______________________|______________________________________|_______|
  756.    |Oct 24-28, 1988       | Resolve mock ballot objections;     |   7   |
  757.    |Honolulu, HI          | produce first real ballot (draft 8) |       |
  758.    _|_______________________|_U_P_E__p_l_a_n_n_i_n_g__b_e_g_i_n_s___________________|_______|
  759.    |[Jan-Feb 1989]        | [First ballot]                      |   8   |
  760.    _|_______________________|______________________________________|_______|
  761.    |Jan 9-11, 1989        | Begin UPE definitions;              |   8   |
  762.    |Ft. Lauderdale, FL    | Technical Reviewer coordination     |       |
  763.    _|_______________________|_o_f__f_i_r_s_t__b_a_l_l_o_t__r_e_s_p_o_n_s_e_s_____________|_______|
  764.    |[Feb-Apr 1989]        | [Ballot resolution]                 |   8   |
  765.    _|_______________________|______________________________________|_______|
  766.    |Apr 24-28, 1989       | Working Group concurrence with      |   9   |
  767.    |Minneapolis, MN       | ballot resolution; produce Draft 9  |       |
  768.    _|_______________________|_f_o_r__r_e_c_i_r_c_u_l_a_t_i_o_n_;__U_P_E__w_o_r_k___________|_______|
  769.    |Jul 10-14, 1989       | UPE work                            |       |
  770.    |San Jose, CA          |                                     |       |
  771.    _|_______________________|______________________________________|_______|
  772.    _|[_O_c_t__1_9_8_9_]______________|_[_F_i_r_s_t__R_e_c_i_r_c_u_l_a_t_i_o_n_]_________________|___9____|
  773.    |[Nov-Feb 1990]        | [Ballot resolution]                 |   9   |
  774.    _|_______________________|______________________________________|_______|
  775.    _|[_A_u_g_-_S_e_p__1_9_9_0_]__________|_[_S_e_c_o_n_d__R_e_c_i_r_c_u_l_a_t_i_o_n_]________________|__1_0____|
  776.    |[Mar 1991]            | [Third Recirculation]               |  11   |
  777.    _|_______________________|______________________________________|_______|
  778.    _|[_J_u_n__1_9_9_1_]______________|_[_F_o_u_r_t_h__R_e_c_i_r_c_u_l_a_t_i_o_n_]________________|_1_1_._1___|   11
  779.    _|_______________________|______________________________________|_______|   11111
  780.  
  781.  
  782.  
  783.                Copyright c 1991 IEEE.  All rights reserved.
  784.       This is an unapproved IEEE Standards Draft, subject to change.
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.    |[Sep 1991]            | [Fifth Recirculation]               | 11.2  |   1
  799.    _|_______________________|______________________________________|_______|   1
  800.    _|[_m_i_d_-_1_9_9_2_]______________|_[_I_E_E_E__S_t_a_n_d_a_r_d__B_o_a_r_d__A_p_p_r_o_v_e_s_?_?_]______|__1_2____|   21
  801.    |[Jul 1990 - Apr 1992] | [Ballot .2a UPE supplement]         |       |   1
  802.    _|_______________________|______________________________________|_______|
  803.  
  804.  END_RATIONALE
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.                Copyright c 1991 IEEE.  All rights reserved.
  850.       This is an unapproved IEEE Standards Draft, subject to change.
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  IEEE Standards documents are developed within the Technical Committees of
  866.  the IEEE Societies and the Standards Coordinating Committees of the IEEE
  867.  Standards Board.  Members of the committees serve voluntarily and without
  868.  compensation.  They are not necessarily members of the Institute.  The
  869.  standards developed within IEEE represent a consensus of the broad
  870.  expertise on the subject within the Institute as well as those activities
  871.  outside of IEEE that have expressed an interest in participating in the
  872.  development of the standard.
  873.  
  874.  Use of an IEEE Standard is wholly voluntary.  The existence of an IEEE
  875.  Standard does not imply that there are no other ways to produce, test,
  876.  measure, purchase, market, or provide other goods and services related to
  877.  the scope of the IEEE Standard.  Furthermore, the viewpoint expressed at
  878.  the time a standard is approved and issued is subject to change brought
  879.  about through developments in the state of the art and comments received
  880.  from users of the standard.  Every IEEE Standard is subjected to review
  881.  at least every five years for revision or reaffirmation.  When a document
  882.  is more than five years old and has not been reaffirmed, it is reasonable
  883.  to conclude that its contents, although still of some value, do not
  884.  wholly reflect the present state of the art.  Users are cautioned to
  885.  check to determine that they have the latest edition of any IEEE
  886.  Standard.
  887.  
  888.  Comments for revision of IEEE Standards are welcome from any interested
  889.  party, regardless of membership affiliation with IEEE.  Suggestions for
  890.  changes in documents should be in the form of a proposed change of text,
  891.  together with appropriate supporting comments.
  892.  
  893.  Interpretations:  Occasionally questions may arise regarding the meaning
  894.  of portions of standards as they relate to specific applications.  When
  895.  the need for interpretations is brought to the attention of the IEEE, the
  896.  Institute will initiate action to prepare appropriate responses.  Since
  897.  IEEE Standards represent a consensus of all concerned interests, it is
  898.  important to ensure that any interpretation has also received the
  899.  concurrence of a balance of interests.  For this reason, the IEEE and the
  900.  members of its technical committees are not able to provide an instant
  901.  response to interpretation requests except in those cases where the
  902.  matter has previously received formal consideration.
  903.  
  904.  Comments on standards and requests for interpretations should be
  905.  addressed to:
  906.  
  907.        Secretary, IEEE Standards Board
  908.        445 Hoes Lane
  909.        P.O. Box 1331
  910.        Piscataway, NJ 08855-1331
  911.  
  912.  
  913.  
  914.  
  915.                Copyright c 1991 IEEE.  All rights reserved.
  916.       This is an unapproved IEEE Standards Draft, subject to change.
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.     __________________________________________________________________
  931.     |IEEE Standards documents are adopted by the Institute of         |
  932.     |Electrical and Electronics Engineers without regard              |
  933.     |to whether their adoption may involve patents                    |
  934.     |on articles, materials, or processes.                            |
  935.     |Such adoption does not assume any liability to any patent owner, |
  936.     |nor does it assume any obligation whatever to parties adopting   |
  937.     _||t_h_e__s_t_a_n_d_a_r_d_s__d_o_c_u_m_e_n_t_s_.__________________________________________||
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.                Copyright c 1991 IEEE.  All rights reserved.
  982.       This is an unapproved IEEE Standards Draft, subject to change.
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.                                  Contents
  1000.  
  1001.  
  1002.                                                                       PAGE
  1003.  
  1004.  Introduction.......................................................    ii
  1005.     Organization of the Standard....................................    ii
  1006.     Base Documents..................................................    ii
  1007.     Related Standards Activities....................................    ii
  1008.  
  1009.  Section 1: General.................................................     1
  1010.     1.1   Scope.....................................................     1
  1011.     1.2   Normative References......................................    13
  1012.     1.3   Conformance...............................................    14
  1013.  
  1014.  Section 2: Terminology and General Requirements....................    21
  1015.     2.1   Conventions...............................................    21
  1016.     2.2   Definitions...............................................    26
  1017.     2.3   Built-in Utilities........................................    58
  1018.     2.4   Character Set.............................................    61
  1019.     2.5   Locale....................................................    69
  1020.     2.6   Environment Variables.....................................   119
  1021.     2.7   Required Files............................................   126
  1022.     2.8   Regular Expression Notation...............................   128
  1023.     2.9   Dependencies on Other Standards...........................   161
  1024.     2.10  Utility Conventions.......................................   172
  1025.     2.11  Utility Description Defaults..............................   182
  1026.     2.12  File Format Notation......................................   198
  1027.     2.13  Configuration Values......................................   204
  1028.  
  1029.  Section 3: Shell Command Language..................................   215
  1030.     3.1   Shell Definitions.........................................   217
  1031.     3.2   Quoting...................................................   220
  1032.     3.3   Token Recognition.........................................   224
  1033.     3.4   Reserved Words............................................   226
  1034.     3.5   Parameters and Variables..................................   228
  1035.     3.6   Word Expansions...........................................   233
  1036.     3.7   Redirection...............................................   249
  1037.     3.8   Exit Status and Errors....................................   255
  1038.     3.9   Shell Commands............................................   258
  1039.     3.10  Shell Grammar.............................................   279
  1040.     3.11  Signals and Error Handling................................   288
  1041.     3.12  Shell Execution Environment...............................   289
  1042.     3.13  Pattern Matching Notation.................................   291
  1043.     3.14  Special Built-in Utilities................................   295
  1044.  
  1045.  Section 4: Execution Environment Utilities.........................   317
  1046.  
  1047.                Copyright c 1991 IEEE.  All rights reserved.
  1048.       This is an unapproved IEEE Standards Draft, subject to change.
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  ii
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.                                                                       PAGE
  1063.  
  1064.     4.1   awk - Pattern scanning and processing language............   317
  1065.     4.2   basename - Return nondirectory portion of pathname........   358
  1066.     4.3   bc - Arbitrary-precision arithmetic language..............   362
  1067.     4.4   cat - Concatenate and print files.........................   383
  1068.     4.5   cd - Change working directory.............................   388
  1069.     4.6   chgrp - Change file group ownership.......................   392
  1070.     4.7   chmod - Change file modes.................................   395
  1071.     4.8   chown - Change file ownership.............................   405
  1072.     4.9   cksum - Write file checksums and sizes....................   409
  1073.     4.10  cmp - Compare two files...................................   416
  1074.     4.11  comm - Select or reject lines common to two files.........   420
  1075.     4.12  command - Execute a simple command........................   424
  1076.     4.13  cp - Copy files...........................................   430
  1077.     4.14  cut - Cut out selected fields of each line of a file......   440
  1078.     4.15  date - Write the date and time............................   445
  1079.     4.16  dd - Convert and copy a file..............................   452
  1080.     4.17  diff - Compare two files..................................   462
  1081.     4.18  dirname - Return directory portion of pathname............   471
  1082.     4.19  echo - Write arguments to standard output.................   475
  1083.     4.20  ed - Edit text............................................   479
  1084.     4.21  env - Set environment for command invocation..............   498
  1085.     4.22  expr - Evaluate arguments as an expression................   503
  1086.     4.23  false - Return false value................................   509
  1087.     4.24  find - Find files.........................................   511
  1088.     4.25  fold - Fold lines.........................................   521
  1089.     4.26  getconf - Get configuration values........................   526
  1090.     4.27  getopts - Parse utility options...........................   531
  1091.     4.28  grep - File pattern searcher..............................   537
  1092.     4.29  head - Copy the first part of files.......................   545
  1093.     4.30  id - Return user identity.................................   549
  1094.     4.31  join - Relational database operator.......................   554
  1095.     4.32  kill - Terminate or signal processes......................   559
  1096.     4.33  ln - Link files...........................................   566
  1097.     4.34  locale - Get locale-specific information..................   570
  1098.     4.35  localedef - Define locale environment.....................   577
  1099.     4.36  logger - Log messages.....................................   583
  1100.     4.37  logname - Return user's login name........................   586
  1101.     4.38  lp - Send files to a printer..............................   589
  1102.     4.39  ls - List directory contents..............................   595
  1103.     4.40  mailx - Process messages..................................   605
  1104.     4.41  mkdir - Make directories..................................   610
  1105.     4.42  mkfifo - Make FIFO special files..........................   614
  1106.     4.43  mv - Move files...........................................   617
  1107.     4.44  nohup - Invoke a utility immune to hangups................   623
  1108.     4.45  od - Dump files in various formats........................   627
  1109.     4.46  paste - Merge corresponding or subsequent lines of
  1110.           files.....................................................   637
  1111.     4.47  pathchk - Check pathnames.................................   642
  1112.  
  1113.                Copyright c 1991 IEEE.  All rights reserved.
  1114.       This is an unapproved IEEE Standards Draft, subject to change.
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.                                                                        iii
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.                                                                       PAGE
  1129.  
  1130.     4.48  pax - Portable archive interchange........................   648
  1131.     4.49  pr - Print files..........................................   665
  1132.     4.50  printf - Write formatted output...........................   672
  1133.     4.51  pwd - Return working directory name.......................   679
  1134.     4.52  read - Read a line from standard input....................   682
  1135.     4.53  rm - Remove directory entries.............................   686
  1136.     4.54  rmdir - Remove directories................................   692
  1137.     4.55  sed - Stream editor.......................................   695
  1138.     4.56  sh - Shell, the standard command language interpreter.....   706
  1139.     4.57  sleep - Suspend execution for an interval.................   713
  1140.     4.58  sort - Sort, merge, or sequence check text files..........   716
  1141.     4.59  stty - Set the options for a terminal.....................   725
  1142.     4.60  tail - Copy the last part of a file.......................   736
  1143.     4.61  tee - Duplicate standard input............................   742
  1144.     4.62  test - Evaluate expression................................   745
  1145.     4.63  touch - Change file access and modification times.........   756
  1146.     4.64  tr - Translate characters.................................   762
  1147.     4.65  true - Return true value..................................   770
  1148.     4.66  tty - Return user's terminal name.........................   772
  1149.     4.67  umask - Get or set the file mode creation mask............   775
  1150.     4.68  uname - Return system name................................   780
  1151.     4.69  uniq - Report or filter out repeated lines in a file......   784
  1152.     4.70  wait - Await process completion...........................   790
  1153.     4.71  wc - Word, line, and byte count...........................   795
  1154.     4.72  xargs - Construct argument list(s) and invoke utility.....   799
  1155.  
  1156.  Section 5: User Portability Utilities Option.......................   807
  1157.  
  1158.  Section 6: Software Development Utilities Option...................   809
  1159.     6.1   ar - Create and maintain library archives.................   809
  1160.     6.2   make - Maintain, update, and regenerate groups of
  1161.           programs..................................................   818
  1162.     6.3   strip - Remove unnecessary information from executable
  1163.           files.....................................................   844
  1164.  
  1165.  Section 7: Language-Independent System Services....................   847
  1166.     7.1   Shell Command Interface...................................   848
  1167.     7.2   Access Environment Variables..............................   849
  1168.     7.3   Regular Expression Matching...............................   849
  1169.     7.4   Pattern Matching..........................................   850
  1170.     7.5   Command Option Parsing....................................   850
  1171.     7.6   Generate Pathnames Matching a Pattern.....................   850
  1172.     7.7   Perform Word Expansions...................................   851
  1173.     7.8   Get POSIX Configurable Variables..........................   851
  1174.     7.9   Locale Control............................................   852
  1175.  
  1176.  Annex A (normative) C Language Development Utilities Option........   855
  1177.     A.1   c89 - Compile Standard C programs.........................   856
  1178.  
  1179.                Copyright c 1991 IEEE.  All rights reserved.
  1180.       This is an unapproved IEEE Standards Draft, subject to change.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  iv
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.                                                                       PAGE
  1195.  
  1196.     A.2   lex - Generate programs for lexical tasks.................   867
  1197.     A.3   yacc - Yet another compiler compiler......................   884
  1198.  
  1199.  Annex B (normative) C Language Bindings Option.....................   907
  1200.     B.1   C Language Definitions....................................   908
  1201.           B.1.1  POSIX Symbols......................................   908
  1202.           B.1.2  Headers and Function Prototypes....................   910
  1203.           B.1.3  Error Numbers......................................   911
  1204.     B.2   C Numerical Limits........................................   911
  1205.           B.2.1  C Macros for Symbolic Limits.......................   912
  1206.           B.2.2  Compile-Time Symbolic Constants for Portability
  1207.                  Specifications.....................................   913
  1208.           B.2.3  Execution-Time Symbolic Constants for Portability
  1209.                  Specifications.....................................   914
  1210.           B.2.4  POSIX.1 C Numerical Limits.........................   915
  1211.     B.3   C Binding for Shell Command Interface.....................   915
  1212.           B.3.1  C Binding for Execute Command......................   916
  1213.           B.3.2  C Binding for Pipe Communications with Programs....   919
  1214.     B.4   C Binding for Access Environment Variables................   925
  1215.     B.5   C Binding for Regular Expression Matching.................   925
  1216.     B.6   C Binding for Match Filename or Pathname..................   934
  1217.     B.7   C Binding for Command Option Parsing......................   937
  1218.     B.8   C Binding for Generate Pathnames Matching a Pattern.......   942
  1219.     B.9   C Binding for Perform Word Expansions.....................   948
  1220.     B.10  C Binding for Get POSIX Configurable Variables............   954
  1221.     B.11  C Binding for Locale Control..............................   957
  1222.  
  1223.  Annex C (normative) FORTRAN Development and Runtime Utilities
  1224.     Options.........................................................   959
  1225.     C.1   asa - Interpret carriage-control characters...............   960
  1226.     C.2   fort77 - FORTRAN compiler.................................   964
  1227.  
  1228.  Annex D (informative) Bibliography.................................   973
  1229.  
  1230.  Annex E (informative) Rationale and Notes..........................   977
  1231.     E.1   General...................................................   977
  1232.     E.2   Terminology and General Requirements......................   978
  1233.     E.3   Shell Command Language....................................   979
  1234.     E.4   Execution Environment Utilities...........................   980
  1235.     E.5   User Portability Utilities Option.........................   993
  1236.     E.6   Software Development Utilities Option.....................   993
  1237.     E.7   Language-Independent System Services......................   994
  1238.     E.8   C Language Development Utilities Option...................   994
  1239.     E.9   C Language Bindings Option................................   995
  1240.     E.10  FORTRAN Development and Runtime Utilities Options.........   996
  1241.  
  1242.  Annex F (informative) Sample National Profile......................   997
  1243.  
  1244.  
  1245.                Copyright c 1991 IEEE.  All rights reserved.
  1246.       This is an unapproved IEEE Standards Draft, subject to change.
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.                                                                          v
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.                                                                       PAGE
  1261.  
  1262.  Annex G (informative) Balloting Instructions.......................  1091
  1263.  
  1264.  Identifier Index...................................................  1105
  1265.  
  1266.  Alphabetic Topical Index...........................................  1111
  1267.  
  1268.  
  1269.  FIGURES
  1270.  
  1271.  Figure B-1  -  Sample _ssss_yyyy_ssss_tttt_eeee_mmmm() Implementation.......................  922
  1272.  Figure B-2  -  Sample _pppp_cccc_llll_oooo_ssss_eeee() Implementation.......................  926
  1273.  Figure B-3  -  Example Regular Expression Matching..................  933
  1274.  Figure B-4  -  Argument Processing with _gggg_eeee_tttt_oooo_pppp_tttt()....................  942
  1275.  
  1276.  
  1277.  TABLES
  1278.  
  1279.  Table 2-1  -  Typographical Conventions.............................   22
  1280.  Table 2-2  -  Regular Built-in Utilities............................   58
  1281.  Table 2-3  -  Character Set and Symbolic Names......................   62
  1282.  Table 2-4  -  Control Character Set.................................   63
  1283.  Table 2-5  -  LC_CTYPE Category Definition in the POSIX Locale......   76
  1284.  Table 2-6  -  Valid Character Class Combinations....................   81
  1285.  Table 2-7  -  LC_COLLATE Category Definition in the POSIX Locale....   84
  1286.  Table 2-8  -  LC_MONETARY Category Definition in the POSIX Locale...   96
  1287.  Table 2-9  -  LC_NUMERIC Category Definition in the POSIX Locale....  101
  1288.  Table 2-10  -  LC_TIME Category Definition in the POSIX Locale......  102
  1289.  Table 2-11  -  LC_MESSAGES Category Definition in the POSIX Locale..  106
  1290.  Table 2-12  -  BRE Precedence.......................................  136
  1291.  Table 2-13  -  ERE Precedence.......................................  139
  1292.  Table 2-14  -  C Standard Operators and Functions...................  171
  1293.  Table 2-15  -  Escape Sequences.....................................  199
  1294.  Table 2-16  -  Utility Limit Minimum Values.........................  205
  1295.  Table 2-17  -  Symbolic Utility Limits..............................  206
  1296.  Table 2-18  -  Optional Facility Configuration Values...............  212
  1297.  Table 4-1  -  awk Expressions in Decreasing Precedence..............  322
  1298.  Table 4-2  -  awk Escape Sequences..................................  347
  1299.  Table 4-3  -  bc Operators..........................................  370
  1300.  Table 4-4  -  ASCII to EBCDIC Conversion............................  459
  1301.  Table 4-5  -  ASCII to IBM EBCDIC Conversion........................  460
  1302.  Table 4-6  -  dirname Examples......................................  474
  1303.  Table 4-7  -  expr Expressions......................................  505
  1304.  Table 4-8  -  od Named Characters...................................  632
  1305.  Table 4-9  -  stty Control Character Names..........................  730
  1306.  Table 4-10  -  stty Circumflex Control Characters...................  731
  1307.  Table 7-1  -  POSIX.1 Numeric-Valued Configurable Variables.........  853
  1308.  Table A-1  -  lex Table Size Declarations...........................  873
  1309.  Table A-2  -  lex Escape Sequences..................................  875
  1310.  
  1311.                Copyright c 1991 IEEE.  All rights reserved.
  1312.       This is an unapproved IEEE Standards Draft, subject to change.
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  vi
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  Table A-3  -  lex ERE Precedence....................................  877
  1329.  Table A-4  -  yacc Internal Limits..................................  903
  1330.  Table B-1  -  POSIX.2 Reserved Header Symbols.......................  911
  1331.  Table B-2  -  _POSIX_C_SOURCE.......................................  911
  1332.  Table B-3  -  C Macros for Symbolic Limits..........................  914
  1333.  Table B-4  -  C Compile-Time Symbolic Constants.....................  916
  1334.  Table B-5  -  C Execution-Time Symbolic Constants...................  916
  1335.  Table B-6  -  Structure Type _rrrr_eeee_gggg_eeee_xxxx______tttt................................  928
  1336.  Table B-7  -  Structure Type _rrrr_eeee_gggg_mmmm_aaaa_tttt_cccc_hhhh______tttt.............................  928
  1337.  Table B-8  -  _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp() _cccc_ffff_llll_aaaa_gggg_ssss Argument.............................  928
  1338.  Table B-9  -  _rrrr_eeee_gggg_eeee_xxxx_eeee_cccc() _eeee_ffff_llll_aaaa_gggg_ssss Argument.............................  928
  1339.  Table B-10  -  _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(), _rrrr_eeee_gggg_eeee_xxxx_eeee_cccc() Return Values...................  932
  1340.  Table B-11  -  _ffff_nnnn_mmmm_aaaa_tttt_cccc_hhhh() _ffff_llll_aaaa_gggg_ssss Argument.............................  937
  1341.  Table B-12  -  Structure Type _gggg_llll_oooo_bbbb______tttt................................  944
  1342.  Table B-13  -  _gggg_llll_oooo_bbbb() _ffff_llll_aaaa_gggg_ssss Argument................................  945
  1343.  Table B-14  -  _gggg_llll_oooo_bbbb() Error Return Values...........................  947
  1344.  Table B-15  -  Structure Type _wwww_oooo_rrrr_dddd_eeee_xxxx_pppp______tttt.............................  950
  1345.  Table B-16  -  _wwww_oooo_rrrr_dddd_eeee_xxxx_pppp() _ffff_llll_aaaa_gggg_ssss Argument.............................  951
  1346.  Table B-17  -  _wwww_oooo_rrrr_dddd_eeee_xxxx_pppp() Return Values..............................  952
  1347.  Table B-18  -  confstr() _nnnn_aaaa_mmmm_eeee Values................................  955
  1348.  Table B-19  -  C Bindings for Numeric-Valued Configurable
  1349.     Variables........................................................  958
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.                Copyright c 1991 IEEE.  All rights reserved.
  1378.       This is an unapproved IEEE Standards Draft, subject to change.
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.                                                                        vii
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.                                Introduction
  1395.  
  1396.  
  1397.  
  1398.  (This Introduction is not a normative part of P1003.2 Information
  1399.  technology -- Portable Operating System Interface (POSIX) -- Part 2:
  1400.  Shell and Utilities, but is included for information only.)
  1401.  
  1402.  The purpose of this standard is to define a standard interface and
  1403.  environment for application programs that require the services of a
  1404.  ``shell'' command language interpreter and a set of common utility
  1405.  programs.  It is intended for systems implementors and application
  1406.  software developers, and is complementary to ISO/IEC 9945-1: 1990 {8}
  1407.  (first in a family of ``POSIX'' standards), which specifies operating
  1408.  system interfaces and source code level functions, based on the UNIX1)
  1409.  system documentation.  This standard, or ``POSIX.2,'' is based upon
  1410.  documentation and the knowledge of existing programs that assume an
  1411.  interface and architecture similar to that described by POSIX.1.  (See
  1412.  1.1 for a full description of the relationship between the standards.)
  1413.  
  1414.  The majority of this standard describes the functions of utilities that
  1415.  can interface with application programs.  The standard also provides
  1416.  high-level language interfaces that the application uses to access these
  1417.  utilities and other useful, related services.  These language-independent
  1418.  service interfaces are temporarily described in terms of their C language
  1419.  bindings.  The C language assumed is that defined by the C Standard:
  1420.  _A_N_S_I/_X_3._1_5_9-_1_9_8_9 _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e _C _S_t_a_n_d_a_r_d produced by Technical
  1421.  Committee X3J11 of the Accredited Standards Committee X3 -- Information
  1422.  Processing Systems.
  1423.  
  1424.  Organization of the Standard
  1425.  
  1426.  The standard is divided into ten parts:
  1427.  
  1428.      - General, including a statement of scope, normative references, and
  1429.        conformance requirements.  (Section 1).
  1430.  
  1431.      - Definitions, general requirements, and the environment available to
  1432.        applications.  (Section 2).
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  __________
  1438.   1) UNIX is a registered trademark of UNIX System Laboratories in the USA
  1439.      and other countries.
  1440.  
  1441.  
  1442.  
  1443.                Copyright c 1991 IEEE.  All rights reserved.
  1444.       This is an unapproved IEEE Standards Draft, subject to change.
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  viii                                                         Introduction
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.      - The shell command interpreter language.  (Section 3).
  1459.  
  1460.      - Descriptions of the utilities in the required ``Execution
  1461.        Environment Utilities.''  (Section 4).
  1462.  
  1463.      - Descriptions of the utilities required for user portability on
  1464.        asynchronous terminals.  (Section 5 [to be provided in a future
  1465.        revision]).
  1466.  
  1467.      - Descriptions of the utilities in the optional ``Software
  1468.        Development Utilities.''  (Section 6).
  1469.  
  1470.      - Language-independent interfaces for high-level programming language
  1471.        access to shell and related services.  (Section 7).
  1472.  
  1473.      - Descriptions of the utilities in the optional ``C Language
  1474.        Development Utilities.''  (Normative Annex A).
  1475.  
  1476.      - C language bindings to the interfaces in Section 6.  (Normative
  1477.        Annex B).
  1478.  
  1479.      - Descriptions of the utilities in the optional ``FORTRAN Development
  1480.        and Runtime Utilities.''  (Normative Annex C).
  1481.  
  1482.  This introduction, the foreword, any footnotes, NOTES accompanying the
  1483.  text, and the _i_n_f_o_r_m_a_t_i_v_e annexes are not considered part of the
  1484.  standard.  Annexes D through G are informative.
  1485.  
  1486.  Base Documents
  1487.  
  1488.  Many of the interfaces and utilities of this standard were adapted from
  1489.  materials in machine-readable forms donated by the following
  1490.  organizations:
  1491.  
  1492.      - AT&T:  the _S_y_s_t_e_m _V _I_n_t_e_r_f_a_c_e _D_e_f_i_n_i_t_i_o_n (_S_V_I_D) {B24},2) Issue 2,
  1493.        Volume 2.  Copyright c 1986, AT&T; reprinted with permission.
  1494.  
  1495.      - The X/Open Company, Ltd.:  the _X/_O_p_e_n _P_o_r_t_a_b_i_l_i_t_y _G_u_i_d_e {B30}
  1496.        {B31}, Issues II and III, Volume 1.  Copyright c 1989, X/Open
  1497.        Company, Ltd; reprinted with permission.
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  __________
  1503.   2) The number in braces corresponds to those of the references in 1.2
  1504.      (or the bibliographic entry in Annex D if the number is preceded by
  1505.      the letter B).
  1506.  
  1507.  
  1508.  
  1509.                Copyright c 1991 IEEE.  All rights reserved.
  1510.       This is an unapproved IEEE Standards Draft, subject to change.
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.                                                                         ix
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.      - University of California, _T_h_e _U_N_I_X _U_s_e_r'_s _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l {B28},
  1525.        4.3 Berkeley Software Distribution, Virtual VAX-11 Version, 1986.
  1526.        Copyright c 1980, 1983, The Regents of the University of
  1527.        California; reprinted with permission.3)
  1528.  
  1529.  Significant reference use was also made of the following books:
  1530.  
  1531.      - Bolsky, Morris I., Korn, David G., _T_h_e _K_o_r_n_S_h_e_l_l _C_o_m_m_a_n_d _a_n_d
  1532.        _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e {B25}, Prentice Hall, Englewood Cliffs, New
  1533.        Jersey (1988).
  1534.  
  1535.      - Aho, Alfred V., Kernighan, Brian W., Weinberger, Peter J., _T_h_e _A_W_K
  1536.        _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e {B21}, Addison-Wesley, Reading, Massachusetts
  1537.        (1988).
  1538.  
  1539.  Many other proposals for functions and utilities were received from the
  1540.  various working group members, who are listed in the Acknowledgements
  1541.  section of this standard.
  1542.  
  1543.  Related Standards Activities
  1544.  
  1545.  Activities to extend this standard to address additional requirements are
  1546.  in progress, and similar efforts can be anticipated in the future.
  1547.  
  1548.  The following areas are under active consideration at this time, or are
  1549.  expected to become active in the near future:4)
  1550.  
  1551.      (1)  Language-independent service descriptions of POSIX.1 {8}
  1552.  
  1553.      (2)  C, Ada, and FORTRAN Language bindings to (1)
  1554.  
  1555.      (3)  Verification testing methods
  1556.  
  1557.      (4)  Realtime facilities
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  __________
  1563.   3) The IEEE is grateful to AT&T, UniForum, and the Regents of the
  1564.      University of California for permission to use their machine-readable
  1565.      materials.
  1566.   4) A _S_t_a_n_d_a_r_d_s _S_t_a_t_u_s _R_e_p_o_r_t that lists all current IEEE Computer
  1567.      Society standards projects is available from the IEEE Computer
  1568.      Society, 1730 Massachusetts Avenue NW, Washington, DC 20036-1903;
  1569.      Telephone: +1 202 371-0101; FAX: +1 202 728-9614.  Working drafts of
  1570.      POSIX standards under development are also available from this
  1571.      office.
  1572.  
  1573.  
  1574.  
  1575.                Copyright c 1991 IEEE.  All rights reserved.
  1576.       This is an unapproved IEEE Standards Draft, subject to change.
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  x                                                            Introduction
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.      (5)  Secure/Trusted System considerations
  1591.  
  1592.      (6)  Network interface facilities
  1593.  
  1594.      (7)  System Administration
  1595.  
  1596.      (8)  Graphical User Interfaces
  1597.  
  1598.      (9)  Profiles describing application- or user-specific combinations
  1599.           of Open Systems standards for:  supercomputing, multiprocessor,
  1600.           and batch extensions; transaction processing; realtime systems;
  1601.           and multiuser systems based on historical models
  1602.  
  1603.     (10)  An overall guide to POSIX-based or related Open Systems
  1604.           standards and profiles
  1605.  
  1606.  Extensions are approved as ``amendments'' or ``revisions'' to this
  1607.  document, following the IEEE and ISO/IEC Procedures.
  1608.  
  1609.  Approved amendments are published separately until the full document is
  1610.  reprinted and such amendments are incorporated in their proper positions.
  1611.  
  1612.  If you have interest in participating in the TCOS working groups
  1613.  addressing these issues, please send your name, address, and phone number
  1614.  to the Secretary, IEEE Standards Board, Institute of Electrical and
  1615.  Electronics Engineers, Inc., P.O. Box 1331, 445 Hoes Lane, Piscataway, NJ
  1616.  08855-1331, and ask to have this forwarded to the chairperson of the
  1617.  appropriate TCOS working group.  If you have interest in participating in
  1618.  this work at the international level, contact your ISO/IEC national body.
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.                Copyright c 1991 IEEE.  All rights reserved.
  1642.       This is an unapproved IEEE Standards Draft, subject to change.
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  Related Standards Activities                                           xi
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  P1003.2 was prepared by the 1003.2 working group, sponsored by the
  1657.  Technical Committee on Operating Systems and Application Environments of
  1658.  the IEEE Computer Society.  At the time this standard was approved, the
  1659.  membership of the 1003.2 working group was as follows:
  1660.  
  1661.                  Technical Committee on Operating Systems
  1662.                     and Application Environments (TCOS)
  1663.  
  1664.                        Chair:   Jehan-Franc,ois Pa^ris
  1665.  
  1666.                         TCOS Standards Subcommittee
  1667.  
  1668.                        Chair:         Jim Isaak
  1669.                        Vice Chairs:   Ralph Barker
  1670.                                       David Dodge
  1671.                                       Robert Bismuth
  1672.                                       Hal Jespersen
  1673.                                       Lorraine Kevra
  1674.                        Treasurer:     Quin Hahn
  1675.                        Secretary:     Shane McCarron
  1676.  
  1677.                       1003.2 Working Group Officials
  1678.  
  1679.               Chair:         Hal Jespersen
  1680.               Vice Chair:    Donald W. Cragun
  1681.               Editors:       Hal Jespersen (1986, 1988-1991)
  1682.                              Maggie Lee (1987-1988)
  1683.               Secretaries:   Helene Armitage (1988-1990)
  1684.                              Dave Grindeland (1991)
  1685.                              Robert J. Makowski (1987-1988)
  1686.  
  1687.                             Technical Reviewers
  1688.  
  1689.       Helene Armitage       Ken Faubel            Gary Miller
  1690.       Keith Bostic          Greger Leijonhufvud   Marc Teitelbaum
  1691.       John Caywood          Bob Lenk              Donn Terry
  1692.       Donald Cragun         Mark Levine           Teoman Topcubasi
  1693.       David Decot           Shane McCarron        David Willcox
  1694.  
  1695.                                Working Group
  1696.  
  1697.       Helene Armitage       Quin Hahn             Jim Oldroyd
  1698.       Brian Baird           Michael J. Hannah     Mark Parenti
  1699.       John R. Barr          Marjorie E. Harris    John Peace
  1700.       Philippe Bertrand     David F. Hinnant      Jon Penner
  1701.       Robert Bismuth        Leon M. Holmes        Gerald Powell
  1702.       Jim Blondeau          Ron Holt              John Quarterman
  1703.  
  1704.  
  1705.  
  1706.  
  1707.                Copyright c 1991 IEEE.  All rights reserved.
  1708.       This is an unapproved IEEE Standards Draft, subject to change.
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  xii                                                          Introduction
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.       James C. Bohem        Randall Howard        Joe Ramus
  1723.       Kathy Bohrer          Steven A. James       Mike Ressler
  1724.       Keith Bostic          Steve Jennings        Grover Righter
  1725.       Phyllis Eve Bregman   Hal Jespersen         Andrew K. Roach
  1726.       Peter Brouwer         Ronald S. Karr        Marco P. Roodzant
  1727.       F. Lee Brown, Jr.     Lorraine C. Kevra     Seth Rosenthal
  1728.       Jonathan Brown        Martin Kirk           Maude Sawyer
  1729.       James A. Capps        Brad Kline            Norman K. Scherer
  1730.       Bill Carpenter        Hiromichi Kogure      Glen Seeds
  1731.       Steve Carter          David Korn            Jim Selkaitis
  1732.       John Caywood          Rick Kuhn             Karen Sheaffer
  1733.       Bob Claeson           Mike Lambert          Del Shoemaker
  1734.       Mark Colburn          Maggie Lee            James Soddy
  1735.       Donald W. Cragun      Perry Lee             Daniel Steinberg
  1736.       Dave Decot            Greger Leijonhufvud   Scott A. Sutter
  1737.       Terence S. Dowling    Bob Lenk              Ravi Tavakley
  1738.       Stephen Dum           Mark Levine           Marc Teitelbaum
  1739.       Dominic Dunlop        Gary Lindgren         Donn Terry
  1740.       Mike Edmonds          John Lomas            Jack Thompson
  1741.       Ron Elliott           Craig Lund            Teoman Topcubasi
  1742.       Richard W. Elwood     Rod MacDonald         Eugene Tsuno
  1743.       Hirsaki Eto           Dan Magenheimer       Geraldine Vitovitch
  1744.       Fran Fadden           Robert J. Makowski    Carl vonLoewenfeldt
  1745.       Ken Faubel            Shane P. McCarron     Mike Wallace
  1746.       Martin C. Fong        Jim McGinness         Alan Weaver
  1747.       Terance Fong          John McGrory          Larry Wehr
  1748.       Glenn Fowler          Stuart McKaig         Bruce Weiner
  1749.       Gary A. Gaudet        Sunil Mehta           N. Ray Wilkes
  1750.       Al Gettier            Bill Middlecamp       David Willcox
  1751.       Timothy D. Gill       Gary W. Miller        Neil Winton
  1752.       Gregory Goddard       Jim Moe               David Woodend
  1753.       Loretta Goudie        Yasushi Nakahara      Morten With
  1754.       Dave Grindeland       Martha Nalebuff       Ken Witte
  1755.       John Lawrence Gregg   Sonya D. Neufer       John Wu
  1756.       Jerry Gross           Landon Noll           Peggy Younger
  1757.       Douglas A. Gwyn       Robin T. O'Neill      Hilary Zaloom
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.                Copyright c 1991 IEEE.  All rights reserved.
  1774.       This is an unapproved IEEE Standards Draft, subject to change.
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  Related Standards Activities                                         xiii
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  The following persons were members of the 1003.2 Balloting Group that
  1789.  approved the standard for submission to the IEEE Standards Board:
  1790.  
  1791.      Derek Kaufman     _X/_O_p_e_n _I_n_s_t_i_t_u_t_i_o_n_a_l _R_e_p_r_e_s_e_n_t_a_t_i_v_e
  1792.      Shane McCarron    _U_N_I_X _I_n_t_e_r_n_a_t_i_o_n_a_l _I_n_s_t_i_t_u_t_i_o_n_a_l _R_e_p_r_e_s_e_n_t_a_t_i_v_e
  1793.      Peter Collinson   _U_S_E_N_I_X _A_s_s_o_c_i_a_t_i_o_n _I_n_s_t_i_t_u_t_i_o_n_a_l _R_e_p_r_e_s_e_n_t_a_t_i_v_e
  1794.  
  1795.  Scott Anderson           Carol J. Harkness        Jim R. Oldroyd
  1796.  Helene Armitage          Craig Harmer             Craig Partridge
  1797.  David Athersych          Dale Harris              Rob Peglar
  1798.  Geoff Baldwin            Myron Hecht              John C. Penney
  1799.  Jerome E. Banasik        Morris J. Herbert        Rand S. Phares
  1800.  Steven E. Barber         David F. Hinnant         P. J. Plauger
  1801.  Robert M. Barned         Lee A. Hollaar           Gerald Powell
  1802.  David R. Bernstein       Ronald Holt Jr.          Scott E. Preece
  1803.  Kabekode V. S. Bhat      Randall Howard           James M. Purtilo
  1804.  Robert Bismuth           Jim Isaak                J. S. Quarterman
  1805.  Jim Blondran             Richard James            Wendy Rauch-Hindin
  1806.  Robert Borochoff         Hal Jespersen            Brad Rhoades
  1807.  Keith Bostic             Greg Jones               Christopher J. Riddick
  1808.  James P. Bound           Michael J. Karels        Andrew K. Roach
  1809.  Joseph Boykin            Lorraine C. Kevra        Arnold Robbins
  1810.  Kevin Brady              Alan W. Kiecker          R. Hughes Rowlands
  1811.  Phyllis Eve Bregman      Jeff Kimmel              Robert Sarr
  1812.  A. Winsor Brown          M. J. Kirk               Norman Schneidewind
  1813.  F. Lee Brown Jr.         Kenneth C. Klingman      Wolfgang Schwabl
  1814.  Luis-Felipe Cabrera      Joshua W. Knight         Richard Scott
  1815.  Nicholas A. Camillone    David Korn               Glen Seeds
  1816.  Andres Caravallo         Takahiko Kuki            Dan Shia
  1817.  Steven L. Carter         Robin B. Lake            Roger Shimada
  1818.  John Caywood             Mike Lambert             Mukesh Singhal
  1819.  Kilnam Chon              Doris Lebovits           Richard Sniderman
  1820.  Chan F. Chong            Maggie Lee               Steven Sommars
  1821.  Robert L. Claeson        Greger Leijonhufvud      Bryan W. Sparks
  1822.  Mark Colburn             Robert M. Lenk           Richard Stallman
  1823.  Kenneth N. Cole          David Lennert            Daniel Steinberg
  1824.  Richard Cornelius        Mark E. Levine           Douglas H. Steves
  1825.  William M. Corwin        Kevin Lewis              Peter Sugar
  1826.  Mike R. Cossey           Kin F. Li                Scott A. Sutter
  1827.  William Cox              James P. Lonjers         Ravi Tavakley
  1828.  Donald W. Cragun         Joseph F. P. Luhukay     Donn Terry
  1829.  Terence Dowling          Paul Lustgarten          Gary F. Tom
  1830.  Stephen A. Dum           Ron Mabe                 A. T. Twigger
  1831.  John D. Earls            Robert J. Makowski       Mark-Rene Uchida
  1832.  Ron Elliott              Roger J. Martin          L. David Umbaugh
  1833.  Richard W. Elwood        Joberto S. B. Martins    Michael W. Vannier
  1834.  David Emery              Yoshihiro Matsumoto      M. B. Wagner
  1835.  
  1836.  
  1837.  
  1838.  
  1839.                Copyright c 1991 IEEE.  All rights reserved.
  1840.       This is an unapproved IEEE Standards Draft, subject to change.
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  xiv                                                          Introduction
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  Philip H. Enslow         Shane McCarron           John W. Walz
  1855.  Ken Faubel               Martin J. McGowan III    Alan G. Weaver
  1856.  Terence Fong             Marshall Kirk McKusick   Larry Wehr
  1857.  Ed Frankenberry          Robert W. McWhirter      Bruce Weiner
  1858.  John A. Gertwagen        Doug Michels             Brian Weis
  1859.  Al Gettier               Gary W. Miller           Peter J. Weyman
  1860.  Michel Gien              James M. Moe             Andrew E. Wheeler
  1861.  Gregory W. Goddard       J. W. Moore              David Willcox
  1862.  Robert C. Groman         Anita Mundkur            Jeff Wubik
  1863.  Judy Guist               Martha Nalebuff          Oren Yuen
  1864.  Gregory Guthrie          Fred Noz                 Jason Zions
  1865.  Michael J. Hannah        Alan F. Nugent
  1866.  
  1867.  When the IEEE Standards Board approved this standard on <_d_a_t_e _t_o _b_e
  1868.  _p_r_o_v_i_d_e_d>, it had the following membership:
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.                                    (to be pasted in by IEEE)
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  END_RATIONALE
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.                Copyright c 1991 IEEE.  All rights reserved.
  1906.       This is an unapproved IEEE Standards Draft, subject to change.
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  Related Standards Activities                                           xv
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.  
  1923.  
  1924.  
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.  
  1932.  
  1933.  
  1934.  
  1935.  
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.                                                              P1003.2/D11.2
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  Information technology -- Portable Operating System Interface (POSIX) --
  1998.  Part 2: Shell and Utilities
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.                             Section 1: General
  2008.  
  2009.  
  2010.  
  2011.  1.1  Scope
  2012.  
  2013.  This standard defines a standard source code level interface to command
  2014.  interpretation, or ``shell,'' services and common utility programs for
  2015.  application programs.  These services and programs are complementary to
  2016.  those specified by ISO/IEC 9945-1: 1990 {8}, hereinafter referred to as
  2017.  ``POSIX.1 {8}.''
  2018.  
  2019.  The standard has been designed to be used by both application programmers
  2020.  and system implementors.  However, it is intended to be a reference
  2021.  document and not a tutorial on the use of the services, the utilities, or
  2022.  the interrelationships between the utilities.
  2023.  
  2024.  The emphasis of this standard is on the shell and utility functionality
  2025.  required by application programs (including ``shell scripts'') and not on
  2026.  the direct interactive use of the shell command language or the utilities
  2027.  by humans.
  2028.  
  2029.  Portions of this standard comprise optional language bindings to system
  2030.  service interfaces.  See, for example, the C Language Bindings Option in
  2031.  Annex B.  This standard is intended to describe language interfaces and
  2032.  utilities in sufficient detail so that an application developer can
  2033.  understand the required interfaces without access to the source code of
  2034.  existing implementations on which they may be based.  Therefore, it does
  2035.  
  2036.  
  2037.                Copyright c 1991 IEEE.  All rights reserved.
  2038.       This is an unapproved IEEE Standards Draft, subject to change.
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  1.1 Scope                                                               1
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2051.  
  2052.  not attempt to describe the source programming language or internal
  2053.  design of the utilities; they should be considered ``black boxes'' that
  2054.  exhibit the described functionality.
  2055.  
  2056.  For language interfaces, or functions, this standard has been defined
  2057.  exclusively at the source code level.  The objective is that a conforming
  2058.  portable application source program can be translated to execute on a
  2059.  conforming implementation.  The standard assumes that the source program
  2060.  may need to be retranslated to produce target code for a new environment
  2061.  prior to execution in that environment.
  2062.  
  2063.  There is no requirement that the base operating system supporting the
  2064.  shell and utilities be one that fully conforms to ISO/IEC 9945-1: 1990
  2065.  {8}.  (The base system could contain a subset of POSIX.1 {8}
  2066.  functionality, enough to support the requirements for this standard, as
  2067.  described in 2.9.1, but that could not claim full conformance to all of
  2068.  POSIX.1 {8}.)  Furthermore, there is no requirement that the shell
  2069.  command interpreter or any of the standard utilities be written as
  2070.  POSIX.1 {8} conforming programs, or be written in any particular
  2071.  language.
  2072.  
  2073.  Although not requiring a fully conforming POSIX.1 {8} base, this standard
  2074.  is based upon documentation and the knowledge of existing programs that
  2075.  assume an interface and architecture similar to that described by
  2076.  POSIX.1 {8}.  Any questions regarding the definition of terms or the
  2077.  semantics of an underlying concept should be referred to POSIX.1 {8}.
  2078.  
  2079.  BEGIN_RATIONALE
  2080.  
  2081.  
  2082.  1.1.1  Scope Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2083.  
  2084.  This standard is one of a family of related standards.  The term POSIX is
  2085.  correctly used to describe this family, and not only its foundation, the
  2086.  operating system interfaces of POSIX.1 {8}.  Therefore, POSIX.2 could
  2087.  colloquially be described as the ``POSIX Shell and Tools Standard.''
  2088.  
  2089.  The interfaces documented for this standard are to and from high-level
  2090.  language application programs and to and from the utilities themselves;
  2091.  the standard does not directly address the interface with users.
  2092.  
  2093.  The ``source code'' interface to the command interpreter is defined in
  2094.  terms of high-level language functions in 7.1.1 or 7.1.2 (such as
  2095.  _s_y_s_t_e_m(), B.3.1, or _p_o_p_e_n(), B.3.2).  There are also other function
  2096.  interfaces, such as those for matching regular expressions in 7.3
  2097.  (_r_e_g_c_o_m_p() in B.5).  Many of the utilities in this standard, and the
  2098.  shell itself, also accept their own command languages or complex
  2099.  directives as input data, which is also referred to as source code.  This
  2100.  data, an ordered series of characters, may be stored in files, or
  2101.  
  2102.  
  2103.                Copyright c 1991 IEEE.  All rights reserved.
  2104.       This is an unapproved IEEE Standards Draft, subject to change.
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  2                                                               1 General
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2117.  
  2118.  ``scripts,'' that are portable between systems without true
  2119.  recompilation.  However, just as with POSIX.1 {8}, the standard addresses
  2120.  only the issue of source code portability between systems; applications
  2121.  using these calls may have to be recompiled or translated when moving
  2122.  from one system to another.
  2123.  
  2124.  There has been considerable debate concerning the appropriate scope of
  2125.  the work represented by this standard.  The following are rational
  2126.  alternatives that have been evaluated:
  2127.  
  2128.      (1)  Define the shell and tools as extensions to POSIX.1 {8}.  This
  2129.           would require a full conforming POSIX.1 {8} system as a base for
  2130.           the new facilities described here.  Vocal proponents for this
  2131.           view have been the members of the POSIX.3 working group, who
  2132.           foresaw difficulties in producing a verification suite standard
  2133.           without having a known operating system base.
  2134.  
  2135.      (2)  Decouple the shell and tools entirely from POSIX.1 {8}.  This
  2136.           would potentially allow the standard to be implemented on such
  2137.           popular operating systems as MVS/TSO, VM/CMS, MS/DOS, VMS, etc.
  2138.           Those systems would not have to provide every minor detail of
  2139.           the POSIX.1 {8} language interfaces to conform under this model-
  2140.           --only enough to support the shell and tools.
  2141.  
  2142.      (3)  Compromise between options 1 and 2.  Base the standard on an
  2143.           interface _s_i_m_i_l_a_r to POSIX.1 {8}, but don't require full
  2144.           conformance.  A simple example would be a Version 7 UNIX System,
  2145.           which could not conform to POSIX.1 {8} without considerable
  2146.           modification.  However, a vendor could support all of the
  2147.           features of this standard without changing its kernel or binary
  2148.           compatibility.  Another example would be a system that conformed
  2149.           to all stated POSIX.1 {8} interfaces, but that didn't have a
  2150.           fully conforming C Standard {7} compiler.  The difficulty with
  2151.           this option is that it makes the stated goal of the working
  2152.           group a bit fuzzier and increases the amount of analysis
  2153.           required for the features included.
  2154.  
  2155.  The working group selected option 3 as its goal.  It chose to retain the
  2156.  full UNIX system-like orientation, but did not wish to arbitrarily
  2157.  deprive legitimate systems that could _a_l_m_o_s_t conform.  No useful feature
  2158.  of shells or commonly-used utilities were discarded to accommodate
  2159.  nonconforming base systems; on the other hand, no deliberate obstacles
  2160.  were arbitrarily erected.  Furthermore, POSIX.1 {8} is still required for
  2161.  its definitions and architectural concepts, which are purposely not
  2162.  repeated in this standard.
  2163.  
  2164.  One concrete example of how the two standards interrelate is in the usage
  2165.  of POSIX.1 {8} function names in the descriptions of utilities in
  2166.  POSIX.2.  There are a number of historical commands that directly mapped
  2167.  
  2168.  
  2169.                Copyright c 1991 IEEE.  All rights reserved.
  2170.       This is an unapproved IEEE Standards Draft, subject to change.
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  1.1 Scope                                                               3
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2183.  
  2184.  into one of the UNIX system calls.  For example:  chmod and _c_h_m_o_d(); ln
  2185.  and _l_i_n_k().  The POSIX.2 working group was faced with the problem of
  2186.  having to define all of the complex interactions ``behind the scenes''
  2187.  for some simple commands.  Creating a file, for example, involves many
  2188.  POSIX.1 {8} concepts, including processes, user IDs, multiple group
  2189.  permissions (which are optional), error conditions, etc.  Rather than
  2190.  enumerating all of these interactions in many places, the POSIX.2 group
  2191.  chose to employ the POSIX.1 {8} function descriptions, where appropriate.
  2192.  See the chmod utility in 4.7 as an example.  The utility description
  2193.  includes the phrase:
  2194.  
  2195.        ... performing actions equivalent to the _c_h_m_o_d() function as
  2196.        defined in the POSIX.1 {8} _c_h_m_o_d() function:
  2197.  
  2198.  This means that the POSIX.2 implementor has to read the POSIX.1 {8}
  2199.  _c_h_m_o_d() description and fully understand all of its functionality,
  2200.  requirements, and side effects, which now don't have to be repeated here.
  2201.  (Admittedly, this makes the POSIX.2 standard a bit more difficult to
  2202.  read, but the working group felt that precision transcended the need for
  2203.  readable or semi-tutorial documents.)
  2204.  
  2205.  The Introduction states that one of the goals of the working group was:
  2206.  ``This interface should be implementable on conforming POSIX.1 {8}
  2207.  systems.''  This implies that the working group has attempted to ensure
  2208.  that no additional functionality or extension is required to implement
  2209.  this standard on the base defined by POSIX.1 {8}.  This is not to say
  2210.  that extensions are not allowed, but that they should not be necessary.
  2211.  The goal ``(7) Utilities and standards for the installation of
  2212.  applications" was once interpreted to mean that an elaborate series of
  2213.  tools was required to install and remove applications, based on complex
  2214.  description files and system databases of capabilities.  An attempt to
  2215.  provide this was rejected by the balloting group and that type of system
  2216.  is now being evaluated by the POSIX.7 System Administration group.
  2217.  However, the original goal remains in the list, because many of the
  2218.  standard utilities are, in fact, targeted specifically for application
  2219.  installation--make, c89, lex, etc.
  2220.  
  2221.  
  2222.  1.1.1.1  Existing Practice. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2223.  
  2224.  The working group would have been very happy to develop a standard that
  2225.  allowed all historical implementations (i.e., those existing prior to the
  2226.  time of publication) to be fully conforming and all historical
  2227.  applications to be Strictly Conforming POSIX Shell Applications without
  2228.  requiring any changes.  Some modifications will be required to reconcile
  2229.  the specific differences between historical implementations; there are
  2230.  many divergent versions of UNIX systems extant and applications have
  2231.  sometimes been written to take advantage of features (or bugs) on
  2232.  specific systems.  Therefore, the working group established a set of
  2233.  goals to maximize the value of the standard it eventually produced.
  2234.  
  2235.                Copyright c 1991 IEEE.  All rights reserved.
  2236.       This is an unapproved IEEE Standards Draft, subject to change.
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  4                                                               1 General
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2249.  
  2250.  These goals are enumerated in the following subclauses.  They are listed
  2251.  in approximate priority sequence, where the first subclause is the most
  2252.  important portability goal.
  2253.  
  2254.  1.1.1.1.1  Preserve Historical Applications
  2255.  
  2256.  The most important priority was to ensure that historical applications
  2257.  continued to operate on conforming implementations.  This required the
  2258.  selection of many utilities and features from the most prevalent
  2259.  historical implementations.  The working group is relying on the
  2260.  following factors:
  2261.  
  2262.      (1)  Many inconsistent historical features will still be supported as
  2263.           _o_b_s_o_l_e_s_c_e_n_t.
  2264.  
  2265.      (2)  Common features of System V and BSD will continue to be
  2266.           supported by their sponsors, even if they aren't included here
  2267.           (just as long as they are not prevented from existing).
  2268.  
  2269.  Therefore, the standard was written so that the large majority of well-
  2270.  written historical applications should continue to operate as Conforming
  2271.  POSIX Shell Applications Using Extensions.
  2272.  
  2273.  1.1.1.1.2  Clean Up the Interfaces
  2274.  
  2275.  The working group chose to extend the benefits of historical UNIX systems
  2276.  by making limited improvements to the utility interfaces; numerous
  2277.  complaints have been heard over the years about the inconsistencies in
  2278.  the command line interface, which have allegedly made it harder for
  2279.  novice users.  Given the constraints of Preserve Historical Applications,
  2280.  the working group has made the following general modifications:
  2281.  
  2282.      (1)  Utilities have been extended to deal with differences in
  2283.           character sets, collating sequences, and some cultural aspects
  2284.           relating to the locale of the user.  (Examples:  new features in
  2285.           regular expressions; new formatting options in date; see 4.15.)
  2286.  
  2287.      (2)  The utility syntax guidelines in 2.10.2 have been applied to
  2288.           almost all of the utilities to promote a consistent interface.
  2289.           The guidelines themselves have been loosened up a bit from their
  2290.           counterparts in the _S_V_I_D.  In many cases historical utilities
  2291.           have not conformed with these guidelines (which were written
  2292.           considerably later than the utilities themselves).  The older
  2293.           interfaces have been maintained in the standard as obsolescent
  2294.           features.  (Examples:  join, sort.)  However, in some cases,
  2295.           such as dd and find, such major surgery was required that the
  2296.           working group decided to leave the historical interfaces as is.
  2297.           ``Fixing'' the interface would mean replacing the command, which
  2298.           would not help applications portability.  So, fixing was limited
  2299.  
  2300.  
  2301.                Copyright c 1991 IEEE.  All rights reserved.
  2302.       This is an unapproved IEEE Standards Draft, subject to change.
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  1.1 Scope                                                               5
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2315.  
  2316.           to relatively minor abuses of the new guidelines, where
  2317.           reasonable consistency could be achieved while still maintaining
  2318.           the general type of interface of the historical version.
  2319.  
  2320.      (3)  Features that were not generally portable across machine
  2321.           architectures or systems have been removed or marked obsolescent
  2322.           and new, more portable interfaces have been introduced.
  2323.           (Examples:  the octal number methods of describing file modes in
  2324.           chmod and other utilities have been marked obsolescent; the
  2325.           symbolic ``ugo'' method has been extended to other utilities,
  2326.           such as umask.)
  2327.  
  2328.      (4)  Features that have proved to be popular in some specific UNIX
  2329.           system variants have been adopted.  (Examples:  diff -c, which
  2330.           originated in BSD systems, and the ``new'' awk, from System V.)
  2331.           Such features were selected given the requirements for balloting
  2332.           group consensus; the features had to be used widely enough to
  2333.           balance accusations of ``creeping featurism'' and violations of
  2334.           the UNIX system ``tools philosophy.''
  2335.  
  2336.      (5)  Unreasonable inconsistencies between otherwise similar
  2337.           interfaces have been reconciled.  (Example:  methods of
  2338.           specifying the patterns to the three grep-_r_e_l_a_t_e_d utilities have
  2339.           been made more consistent in the standard's single grep.)
  2340.  
  2341.      (6)  When irreconcilable differences arose between versions of
  2342.           historical utilities, new interfaces (utility names or syntax)
  2343.           were sometimes added in their places.  The working group
  2344.           resisted the urge to deviate significantly from historical
  2345.           practice; the new interfaces are generally consistent with the
  2346.           philosophy of historical systems and represent comparable
  2347.           functionality to the interfaces being replaced.  In some cases,
  2348.           System V and BSD had diverged (such as with echo and sum) so
  2349.           significantly that no compromises for a common interface were
  2350.           possible.  In these cases, either the divergent features were
  2351.           omitted or an entirely new command name was selected (such as
  2352.           with printf and cksum).
  2353.  
  2354.      (7)  Arbitrary limits to utility operations have been removed.
  2355.           (Example:  some historical ed utilities have very limited
  2356.           capabilities for dealing with large files or long input lines.)
  2357.  
  2358.      (8)  Arbitrary limitations on historical extensions have been
  2359.           eliminated.  (Example:  regular expressions have been described
  2360.           so that the popular \< ...  \> extension is allowed.)
  2361.  
  2362.      (9)  Input and output formats have been specified in more detail than
  2363.           historical implementations have required, allowing applications
  2364.           to more effectively operate in pipelines with these utilities.
  2365.  
  2366.  
  2367.                Copyright c 1991 IEEE.  All rights reserved.
  2368.       This is an unapproved IEEE Standards Draft, subject to change.
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  6                                                               1 General
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2381.  
  2382.           (Example:  comm.)
  2383.  
  2384.  Thus, in many cases the working group could be accused of ``violating
  2385.  Existing Practice,'' and in fact received some balloting objections to
  2386.  that effect from implementors (although rarely from users or application
  2387.  developers).  The working group was sensitive to charges that it was
  2388.  engaged in arbitrary software engineering rather than merely codifying
  2389.  existing practice.  When changes were made, they were always written to
  2390.  preserve historical applications, but to move new conforming applications
  2391.  into a more consistent, portable environment.  This strategy obviously
  2392.  requires changes to historical implementations; the working group
  2393.  carefully evaluated each change, weighing the value to users against the
  2394.  one-time costs of adding the new interfaces (and of possibly breaking
  2395.  applications that took advantage of bugs), generally siding with the
  2396.  users when the costs to implementations and applications was not
  2397.  excessively high.
  2398.  
  2399.  In some cases, changes were reluctantly made that could conceivably break
  2400.  some historical applications; the working group allowed these only in the
  2401.  face of practices it considered rare or significantly misguided.
  2402.  
  2403.  1.1.1.1.3  Allow Historical Conforming Applications
  2404.  
  2405.  It is likely that many historical shell scripts will be Strictly
  2406.  Conforming POSIX.2 Applications without requiring modifications.
  2407.  Developers have long been aware of the differences among the historical
  2408.  UNIX system variants and have avoided the nonportable aspects to increase
  2409.  the scope of their applications' marketplace.  However, the previous goal
  2410.  of a consistent interface was considered to be quite important, so there
  2411.  will be modifications required to some applications if they wish to be
  2412.  maximally portable in the future.
  2413.  
  2414.  1.1.1.1.4  Preserve Historical Implementations
  2415.  
  2416.  As explained in 1.1.1.1.2, the requirements for portability and a
  2417.  consistent interface have caused the working group to add new utilities
  2418.  and features.  No historical implementations contained all of the
  2419.  attributes required by the working group.  Therefore, this lowest
  2420.  priority goal fell victim to the preceding goals, and every known
  2421.  historical implementation will require some modifications to conform to
  2422.  this standard.
  2423.  
  2424.  The working group took care to ensure that the implementations could add
  2425.  the new or modified features without breaking the operation of existing
  2426.  applications.  (Note that the standard utilities are not considered
  2427.  applications in this regard, but are part of the implementation.  In
  2428.  fact, many or most of the utilities named by this standard will have to
  2429.  change to some extent.)
  2430.  
  2431.  
  2432.  
  2433.                Copyright c 1991 IEEE.  All rights reserved.
  2434.       This is an unapproved IEEE Standards Draft, subject to change.
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  1.1 Scope                                                               7
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2447.  
  2448.  1.1.1.2  Outside the Scope. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2449.  
  2450.  The following areas are outside the scope of this standard.  This
  2451.  subclause explains more of the rationale behind the exclusions.  (It
  2452.  should be noted that this is not an official list.  It was not part of
  2453.  the Project Authorization Request submitted to the IEEE, but was devised
  2454.  as a guide to keep the working group discussions on track.)
  2455.  
  2456.      (1)  _O_p_e_r_a_t_i_n_g _s_y_s_t_e_m _a_d_m_i_n_i_s_t_r_a_t_i_v_e _c_o_m_m_a_n_d_s (_p_r_i_v_i_l_e_g_e_d _p_r_o_c_e_s_s_e_s,
  2457.           _s_y_s_t_e_m _p_r_o_c_e_s_s_e_s, _d_a_e_m_o_n_s, _e_t_c.).
  2458.  
  2459.           The working group followed the lead of the POSIX.1 {8} group in
  2460.           this instance.  Administrative commands were felt to be too
  2461.           implementation dependent and not useful for application
  2462.           portability.  Subsequent to this decision, a separate POSIX.7
  2463.           working group was formed to deal with this area of ``operator
  2464.           portability.''  It is anticipated that utilities needed for
  2465.           system administration will be closely coordinated with the
  2466.           POSIX.2 working group.
  2467.  
  2468.      (2)  _C_o_m_m_a_n_d_s _r_e_q_u_i_r_e_d _f_o_r _t_h_e _i_n_s_t_a_l_l_a_t_i_o_n, _c_o_n_f_i_g_u_r_a_t_i_o_n, _o_r
  2469.           _m_a_i_n_t_e_n_a_n_c_e _o_f _o_p_e_r_a_t_i_n_g _s_y_s_t_e_m_s _o_r _f_i_l_e _s_y_s_t_e_m_s.
  2470.  
  2471.           This area is similar to item (1).  System installation is
  2472.           contrasted against the application installation portion of the
  2473.           Scope by its orientation to installing the operating system
  2474.           itself, versus application programs.  The exclusion of operating
  2475.           system installation facilities should not be interpreted to mean
  2476.           that the application installation procedures _c_a_n_n_o_t be used for
  2477.           installing operating system components.  The proposed interface
  2478.           for this area encountered stiff resistance from the balloting
  2479.           group in Draft 8 and was temporarily withdrawn.  As described in
  2480.           Annex E.4, a decision of the balloting group is pending on
  2481.           whether to begin work on a supplement to this standard
  2482.           (POSIX.2b) for application installation.
  2483.  
  2484.      (3)  _N_e_t_w_o_r_k_i_n_g _c_o_m_m_a_n_d_s.
  2485.  
  2486.           These were excluded because they are deeply involved with other
  2487.           standards making bodies and are probably too complicated.  In
  2488.           this case, several working groups were formed within the POSIX
  2489.           family to deal with this.  It is anticipated that utilities
  2490.           needed for networking, if any, will be closely coordinated with
  2491.           the POSIX.2 working group.  (In early drafts of this standard,
  2492.           which predated the formation of the networking-specific POSIX
  2493.           working groups, the historical ``UNIX system to UNIX system copy
  2494.           [UUCP]'' programs and protocols were included.  These
  2495.           descriptions have been removed in deference to a more
  2496.           appropriate working group.)
  2497.  
  2498.  
  2499.                Copyright c 1991 IEEE.  All rights reserved.
  2500.       This is an unapproved IEEE Standards Draft, subject to change.
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  8                                                               1 General
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2513.  
  2514.      (4)  _T_e_r_m_i_n_a_l _c_o_n_t_r_o_l _o_r _u_s_e_r-_i_n_t_e_r_f_a_c_e _p_r_o_g_r_a_m_s (_e._g., _v_i_s_u_a_l
  2515.           _s_h_e_l_l_s, _v_i_s_u_a_l _e_d_i_t_o_r_s, _w_i_n_d_o_w _m_a_n_a_g_e_r_s, _c_o_m_m_a_n_d _h_i_s_t_o_r_y
  2516.           _m_e_c_h_a_n_i_s_m_s, _e_t_c.).
  2517.  
  2518.           This is probably the most contentious exclusion.  A common
  2519.           complaint about many UNIX systems is how they're not very ``user
  2520.           friendly.''  Some people have hoped that the interface to users
  2521.           could be standardized with mice, icon-based desktop metaphors,
  2522.           and so forth.  This standard neatly sidesteps those concerns by
  2523.           reminding its audience that it is an application portability
  2524.           standard, and therefore has little relationship to the manner in
  2525.           which users manage their terminals.
  2526.  
  2527.           However, this guideline was not meant to apply to applications.
  2528.           It is perfectly reasonable for an application to assume it can
  2529.           have a user interacting with it.  That is why such facilities as  1
  2530.           displaying strings (with printf) without <newline>_s, stty, and    1
  2531.           various prompting utilities are included in the standard.
  2532.  
  2533.           The interfaces in this standard are very oriented to command
  2534.           lines being issued by shell scripts, or through the _s_y_s_t_e_m() or
  2535.           _p_o_p_e_n() functions.  Therefore, interactive text editors, pagers,
  2536.           and other user interface tools have been omitted for now.
  2537.           Alternatively, other standards bodies, such as X3H3.6 and the
  2538.           IEEE TCOS P1201 working group, are devising interfaces that
  2539.           could possibly be more useful and long-lived than any prescribed
  2540.           by POSIX.2.
  2541.  
  2542.           There is one area of this subject that will be addressed by
  2543.           POSIX.2.  The scope of the working group has been expanded to
  2544.           include what is being termed the _U_s_e_r _P_o_r_t_a_b_i_l_i_t_y _E_x_t_e_n_s_i_o_n,
  2545.           POSIX.2a.  This will be published as a supplement to this
  2546.           standard and have the goal of providing a portable environment
  2547.           for relatively expert time-sharing or software development
  2548.           users.  It will not attempt to deal with mice or windows or
  2549.           other advanced interfaces at this time, but should cover many of
  2550.           the terminal-oriented utilities, such as a full-screen editor,
  2551.           currently avoided by this edition of POSIX.2.
  2552.  
  2553.      (5)  _G_r_a_p_h_i_c_s _p_r_o_g_r_a_m_s _o_r _i_n_t_e_r_f_a_c_e_s.
  2554.  
  2555.           See the comments on user interface, above.
  2556.  
  2557.      (6)  _T_e_x_t _f_o_r_m_a_t_t_i_n_g _p_r_o_g_r_a_m_s _o_r _l_a_n_g_u_a_g_e_s.
  2558.  
  2559.           The existing text formatting languages are generally too
  2560.           primitive in scope to satisfy many users, who have relied on a
  2561.           myriad of macro languages.  There is an ISO standard text
  2562.           description language, SGML, but this has had insufficient
  2563.  
  2564.  
  2565.                Copyright c 1991 IEEE.  All rights reserved.
  2566.       This is an unapproved IEEE Standards Draft, subject to change.
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  1.1 Scope                                                               9
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2579.  
  2580.           exposure to the UNIX system community for standardization as
  2581.           part of POSIX at this time.
  2582.  
  2583.      (7)  _D_a_t_a_b_a_s_e _p_r_o_g_r_a_m_s _o_r _i_n_t_e_r_f_a_c_e_s (_e._g.  _S_Q_L, _e_t_c.).
  2584.  
  2585.           These interfaces are the province of other standards bodies.
  2586.  
  2587.  
  2588.  1.1.1.3  Language-Independent Descriptions. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  2589.           _o_f _P_1_0_0_3._2)
  2590.  
  2591.  The POSIX.1 {8} and POSIX.5 working groups are currently engaged in
  2592.  developing the model for language-independent descriptions of system
  2593.  services.  When complete, it will allow the C language bias of the
  2594.  POSIX.1 {8} standard to be excised and C will take its place among other
  2595.  language bindings that interface with the core services descriptions.
  2596.  The POSIX.2 working group did not wish to duplicate effort, and has
  2597.  therefore waited until POSIX.1 {8} achieves progress in this area.  Thus,
  2598.  like the first version of POSIX.1 {8}, the initial drafts of POSIX.2
  2599.  start life as a C-only standard, with language independence scheduled to
  2600.  be included in a later draft.  Fortunately, this standard is
  2601.  substantially less involved with C than POSIX.1 {8} is.  In fact, all of
  2602.  the C interfaces are entirely optional.
  2603.  
  2604.  1.1.1.4  Base Documents. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2605.  
  2606.  The working group consulted a number of documents in the course of its
  2607.  deliberations, to select utilities and features.  There were five primary
  2608.  documents that started off the process:
  2609.  
  2610.      (1)  The _S_y_s_t_e_m _V _I_n_t_e_r_f_a_c_e _D_e_f_i_n_i_t_i_o_n (_S_V_I_D), Issue 2, Volume 2.
  2611.  
  2612.      (2)  The _X/_O_p_e_n _P_o_r_t_a_b_i_l_i_t_y _G_u_i_d_e, (_X_P_G), Issues II and III, Volume
  2613.           1.
  2614.  
  2615.      (3)  _T_h_e _U_N_I_X _U_s_e_r'_s _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l, 4.3 Berkeley Software
  2616.           Distribution, Virtual VAX-11 Version.  (The printed
  2617.           documentation as well as the online versions provided with the
  2618.           BSD ``Tahoe'' and ``Reno'' distributions were considered as one
  2619.           base document for the POSIX.2 work.)
  2620.  
  2621.      (4)  _T_h_e _K_o_r_n_S_h_e_l_l _C_o_m_m_a_n_d _a_n_d _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e, by Bolsky and
  2622.           Korn.
  2623.  
  2624.      (5)  _T_h_e _A_W_K _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e, by Aho, Kernighan, and Weinberger.
  2625.  
  2626.  The _X_P_G was used most heavily in initial deliberations about which
  2627.  utilities and features to include.  The X/Open companies had done a very
  2628.  thorough job in analyzing the _S_V_I_D and other standards to compile a list
  2629.  
  2630.  
  2631.                Copyright c 1991 IEEE.  All rights reserved.
  2632.       This is an unapproved IEEE Standards Draft, subject to change.
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  10                                                              1 General
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2645.  
  2646.  of the most useful and portable utilities.  They carefully marked many
  2647.  features that had portability problems and the working group avoided them
  2648.  for this standard.
  2649.  
  2650.  AT&T, X/Open, and Berkeley provided machine-readable documentation for
  2651.  the use of the working group.  However, due to very substantial
  2652.  differences in formatting standards, there is little resemblance between
  2653.  some of the utilities described here and their cousins in the _S_V_I_D, _X_P_G,
  2654.  and BSD user manual.  Nevertheless, early usage of these documents was an
  2655.  invaluable aid in the production of the standard and the POSIX.2 working
  2656.  group extends its sincere thanks to all three organizations for their
  2657.  generous cooperation.
  2658.  
  2659.  The biggest divergence in POSIX.2's documentation has been its philosophy
  2660.  of fully specifying interfaces.  The _S_V_I_D and _X_P_G are oriented solely
  2661.  towards application portability.  Implementors would have a difficult
  2662.  time writing some of these utilities from the descriptions alone.  In
  2663.  fact, both documents freely rely on the potential implementors licensing
  2664.  the source code for the reference systems to complete the specification.
  2665.  The POSIX.2 standard, on the other hand, also has implementors in its
  2666.  audience and it strove to expand its descriptions wherever useful and
  2667.  feasible.  For example, it makes use of BNF grammars to describe complex
  2668.  syntaxes.  It attempts to describe the interactions between options,
  2669.  operands, and environment variables, where conflicts can exist.  It also
  2670.  attempts to describe all of the useful utility input and output formats.
  2671.  The goal here was to allow application developers to write filters or
  2672.  other programs that could parse the output of any of these utilities or
  2673.  to provide meaningful input from their programs.  To the working group's
  2674.  knowledge, this is a task never before attempted for the historical UNIX
  2675.  system commands-the source code was always so readily available to anyone
  2676.  who really needed to know this information.
  2677.  
  2678.  The two commercial books listed were used as reference materials in
  2679.  preparing information on the shell and the _a_w_k language that was more
  2680.  recent and complete than AT&T's or X/Open's documentation.
  2681.  
  2682.  
  2683.  1.1.1.5  History. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2684.  
  2685.  The _1_9_8_4 /_u_s_r/_g_r_o_u_p _S_t_a_n_d_a_r_d was originally intended to include the shell
  2686.  and user level commands.  However, the /usr/group (now known as
  2687.  ``UniForum'') Standards Committee was unable to begin this effort, due to
  2688.  the complexity of the system call and library functions that it
  2689.  eventually did publish.
  2690.  
  2691.  A shell was referred to in the _s_y_s_t_e_m() function defined by _A_N_S_I/_X_3._1_5_9-
  2692.  _1_9_8_9 _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e _C _S_t_a_n_d_a_r_d, but no syntax for the shell command
  2693.  language was attempted.
  2694.  
  2695.  
  2696.  
  2697.                Copyright c 1991 IEEE.  All rights reserved.
  2698.       This is an unapproved IEEE Standards Draft, subject to change.
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  1.1 Scope                                                              11
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2711.  
  2712.  As the first version of POSIX.1 {8} neared completion, it became apparent
  2713.  that the usefulness of POSIX would be diminished if no shell or utilities
  2714.  were defined.  Therefore, the POSIX.2 working group was formed in January
  2715.  1986 at the Denver, Colorado, meeting of POSIX.1 {8} to address this
  2716.  concern.
  2717.  
  2718.  The progress of the working group has seemed rather slow during the more
  2719.  than three years of its existence.  This is primarily because its
  2720.  membership had substantial overlap with the POSIX.1 {8} working group;
  2721.  for example, the Chair of POSIX.2 was also the Technical Editor of
  2722.  POSIX.1 {8} (and POSIX.2 as well!) at the time.  And, meetings were
  2723.  arbitrarily shortened to allow the POSIX.1 {8} group to move forward as
  2724.  quickly as possible.
  2725.  
  2726.  
  2727.  1.1.1.6  Internationalization. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2728.  
  2729.  Some of the utilities and concepts described in this standard contain
  2730.  requirements that standardize multilingual and multicultural support.
  2731.  Most of the internationalized support for this standard was proposed by
  2732.  the UniForum Technical Committee Subcommittee on Internationalization, at
  2733.  the request of the POSIX.2 working group.
  2734.  
  2735.  UniForum, a nonprofit organization, organizes subcommittees of Technical
  2736.  Committees to do standards research on different topics pertinent to
  2737.  POSIX.  The UniForum Subcommittee on Internationalization is one such
  2738.  group.  It was formed to propose and promote standard internationalized
  2739.  extensions to POSIX-based systems.  The POSIX.2 working group and the
  2740.  UniForum Subcommittee on Internationalization coordinated their work by
  2741.  the use of liaison members, who attended the meetings of both groups.
  2742.  The interaction between the two groups started when POSIX.2 asked the
  2743.  Subcommittee on Internationalization to provide internationalized support
  2744.  for regular expressions.  Later, the Subcommittee on Internationalization
  2745.  was charged with identifying areas in the standard needing changes for
  2746.  internationalized support and proposing those changes.
  2747.  
  2748.  1.1.1.7  Test Methods. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  2749.  
  2750.  The POSIX.3 working group has worked on a test methods specification for
  2751.  verifying conformance to POSIX standards in general and POSIX.1 {8} and
  2752.  POSIX.2 in particular.  Test methods for POSIX.2 should be published as a
  2753.  separate document1) sometime after POSIX.2 is approved.
  2754.  
  2755.  
  2756.  
  2757.  __________
  2758.   1) See the Foreword for information on the activities of other POSIX
  2759.      working groups.
  2760.  
  2761.  
  2762.  
  2763.                Copyright c 1991 IEEE.  All rights reserved.
  2764.       This is an unapproved IEEE Standards Draft, subject to change.
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  12                                                              1 General
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2777.  
  2778.  1.1.1.8  Organization of the Standard. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  2779.           _P_1_0_0_3._2)
  2780.  
  2781.  The standard document is organized into sections.  Some of these, such as
  2782.  the Scope in 1.1, are mandated by ISO/IEC, the IEEE, and other standards
  2783.  bodies.  The remainder of the document is organized into small sections
  2784.  for the convenience of the working group and others.  It has been
  2785.  suggested that all of the utility descriptions (and maybe the functions,
  2786.  too) should be lumped into one large section, all in alphabetical order.
  2787.  This would presumably make it easier for some users to use the document
  2788.  as a reference document.  The working group deliberately chose to not
  2789.  organize it in this way, for the following reasons:
  2790.  
  2791.      (1)  Certain sections are optional.  It is more convenient for the
  2792.           document's internal references, and also for people specifying
  2793.           systems, if these optional sections are in large pieces, rather
  2794.           than a detailed list of utility names.
  2795.  
  2796.      (2)  Future supplements to this standard will be adding new utilities
  2797.           that will also be optional.  It would be confusing to try to
  2798.           merge documents at a level below major sections (chapters).
  2799.  
  2800.  END_RATIONALE
  2801.  
  2802.  
  2803.  
  2804.  1.2  Normative References
  2805.  
  2806.  The following standards contain provisions which, through references in
  2807.  this text, constitute provisions of this standard.  At the time of
  2808.  publication, the editions indicated were valid.  All standards are
  2809.  subject to revision, and parties to agreements based on this part of this
  2810.  International Standard are encouraged to investigate the possibility of
  2811.  applying the most recent editions of the standards listed below.  Members
  2812.  of IEC and ISO maintain registers of currently valid International
  2813.  Standards.
  2814.  
  2815.  {1}   ISO/IEC 646: 1983,2) _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g--_I_S_O _7-_b_i_t _c_o_d_e_d
  2816.        _c_h_a_r_a_c_t_e_r _s_e_t _f_o_r _i_n_f_o_r_m_a_t_i_o_n _i_n_t_e_r_c_h_a_n_g_e.
  2817.  
  2818.  
  2819.  
  2820.  __________
  2821.   2) Under revision.  (This notation is meant to explicitly reference the
  2822.      1990 Draft International Standard version of ISO/IEC 646.)
  2823.  
  2824.      ISO/IEC documents can be obtained from the ISO office, 1, rue de
  2825.      Varembe', Case Postale 56, CH-1211, Gene`ve 20, Switzerland/Suisse.
  2826.  
  2827.  
  2828.  
  2829.                Copyright c 1991 IEEE.  All rights reserved.
  2830.       This is an unapproved IEEE Standards Draft, subject to change.
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  1.2 Normative References                                               13
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2843.  
  2844.  {2}   ISO 1539: 1980, _P_r_o_g_r_a_m_m_i_n_g _l_a_n_g_u_a_g_e_s--_F_O_R_T_R_A_N.
  2845.  
  2846.  {3}   ISO 4217: 1987, _C_o_d_e_s _f_o_r _t_h_e _r_e_p_r_e_s_e_n_t_a_t_i_o_n _o_f _c_u_r_r_e_n_c_i_e_s _a_n_d
  2847.        _f_u_n_d_s.
  2848.  
  2849.  {4}   ISO 4873: 1986, _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g--_I_S_O _8-_b_i_t _c_o_d_e _f_o_r
  2850.        _i_n_f_o_r_m_a_t_i_o_n _i_n_t_e_r_c_h_a_n_g_e--_S_t_r_u_c_t_u_r_e _a_n_d _r_u_l_e _f_o_r _i_m_p_l_e_m_e_n_t_a_t_i_o_n.
  2851.  
  2852.  {5}   ISO 8859-1: 1987, _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g--_8-_b_i_t _s_i_n_g_l_e-_b_y_t_e _c_o_d_e_d
  2853.        _g_r_a_p_h_i_c _c_h_a_r_a_c_t_e_r _s_e_t_s--_P_a_r_t _1: _L_a_t_i_n _a_l_p_h_a_b_e_t _N_o. _1.
  2854.  
  2855.  {6}   ISO 8859-2: 1987, _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g--_8-_b_i_t _s_i_n_g_l_e-_b_y_t_e _c_o_d_e_d
  2856.        _g_r_a_p_h_i_c _c_h_a_r_a_c_t_e_r _s_e_t_s--_P_a_r_t _2: _L_a_t_i_n _a_l_p_h_a_b_e_t _N_o. _2.
  2857.  
  2858.  {7}   ISO/IEC 9899: 1990, _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g _s_y_s_t_e_m_s--_P_r_o_g_r_a_m_m_i_n_g      1
  2859.        _l_a_n_g_u_a_g_e_s--_C.
  2860.  
  2861.  {8}   ISO/IEC 9945-1: 1990, _I_n_f_o_r_m_a_t_i_o_n _t_e_c_h_n_o_l_o_g_y--_P_o_r_t_a_b_l_e _O_p_e_r_a_t_i_n_g
  2862.        _S_y_s_t_e_m _I_n_t_e_r_f_a_c_e (_P_O_S_I_X)--_P_a_r_t _1: _S_y_s_t_e_m _A_p_p_l_i_c_a_t_i_o_n _P_r_o_g_r_a_m
  2863.        _I_n_t_e_r_f_a_c_e (_A_P_I) [_C _L_a_n_g_u_a_g_e]
  2864.  
  2865.  
  2866.  
  2867.  1.3  Conformance
  2868.  
  2869.  
  2870.  1.3.1  Implementation Conformance
  2871.  
  2872.  1.3.1.1  Requirements
  2873.  
  2874.  A _c_o_n_f_o_r_m_i_n_g _i_m_p_l_e_m_e_n_t_a_t_i_o_n shall meet all of the following criteria:
  2875.  
  2876.      (1)  The system shall support all required interfaces defined within
  2877.           this standard.  These interfaces shall support the functional
  2878.           behavior described herein.  The system shall provide the shell
  2879.           command language described in Section 3 and the utilities in
  2880.           Section 4.
  2881.  
  2882.      (2)  The system may provide one or more of the following:  the
  2883.           Software Development Utilities Option, the C Language Bindings
  2884.           Option, the C Language Development Utilities Option, the FORTRAN
  2885.           Development Utilities Option, or the FORTRAN Runtime Utilities
  2886.           Option.  When an implementation claims that an optional facility
  2887.           is provided, all of its constituent parts shall be provided.
  2888.  
  2889.      (3)  The system may provide additional or enhanced utilities,
  2890.           functions, or facilities not required by this standard.
  2891.           Nonstandard extensions should be identified as such in the
  2892.           system documentation.  Nonstandard extensions, when used, may
  2893.  
  2894.  
  2895.                Copyright c 1991 IEEE.  All rights reserved.
  2896.       This is an unapproved IEEE Standards Draft, subject to change.
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  14                                                              1 General
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  2909.  
  2910.           change the behavior of utilities, functions, or facilities
  2911.           defined by this standard.  In such cases, the implementation's
  2912.           conformance document (see 2.2.1.2) shall define an execution
  2913.           environment (i.e., shall provide general operating instructions)
  2914.           in which an application can be run with the behavior specified
  2915.           by the standard.  In no case shall such an environment require
  2916.           modification of a Strictly Conforming POSIX.2 Application.
  2917.  
  2918.  
  2919.  1.3.1.2  Documentation
  2920.  
  2921.  A conformance document with the following information shall be available
  2922.  for an implementation claiming conformance to this standard.  The
  2923.  conformance document shall have the same structure as this standard, with
  2924.  the information presented in the appropriately numbered sections;
  2925.  sections that consist solely of subordinate section titles, with no other
  2926.  information, are not required.
  2927.  
  2928.  The conformance document shall not contain information about extended
  2929.  facilities or capabilities outside the scope of this standard, unless
  2930.  those extensions affect the behavior of a Strictly Conforming POSIX.2
  2931.  Application; in such cases, the documentation required by the previous
  2932.  subclause shall be included.
  2933.  
  2934.  The conformance document shall contain a statement that indicates the
  2935.  full name, number, and date of the standard that applies.  The
  2936.  conformance document may also list software standards approved by ISO/IEC
  2937.  or any ISO/IEC member body that are available for use by a Conforming
  2938.  POSIX.2 Application.  It should indicate whether it is based on a fully-
  2939.  conformant POSIX.1 {8} system.  Applicable characteristics where
  2940.  documentation is required by one of these standards, or by standards of
  2941.  government bodies, may also be included.
  2942.  
  2943.  The conformance document shall describe the symbolic values found in
  2944.  2.13.2, stating values, the conditions under which those values can
  2945.  change, and the limits of such variations, if any.
  2946.  
  2947.  The conformance document shall describe the behavior of the
  2948.  implementation for all implementation-defined features defined in this
  2949.  standard.  This requirement shall be met by listing these features and
  2950.  providing either a specific reference to the system documentation or
  2951.  providing full syntax and semantics of these features.  When the value or
  2952.  behavior in the implementation is designed to be variable or customizable
  2953.  on each instantiation of the system, the implementation provider shall
  2954.  document the nature and permissible ranges of this variation.  When
  2955.  information required by this standard is related to the underlying
  2956.  operating system and is already available in the POSIX.1 {8} conformance
  2957.  document, the implementation need not duplicate this information in the
  2958.  POSIX.2 conformance document, but may provide a cross-reference for this
  2959.  purpose.
  2960.  
  2961.                Copyright c 1991 IEEE.  All rights reserved.
  2962.       This is an unapproved IEEE Standards Draft, subject to change.
  2963.  
  2964.  
  2965.  
  2966.  
  2967.  
  2968.  1.3 Conformance                                                        15
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  2975.  
  2976.  The conformance document may specify the behavior of the implementation
  2977.  for those features where this standard states that implementations may
  2978.  vary or where features are identified as undefined or unspecified.
  2979.  
  2980.  No specifications other than those described in this subclause (1.3.1.2)
  2981.  shall be present in the conformance document.
  2982.  
  2983.  The phrase ``shall be documented'' in this standard means that
  2984.  documentation of the feature shall appear in the conformance document, as
  2985.  described previously, unless the system documentation is explicitly
  2986.  mentioned.
  2987.  
  2988.  The system documentation should also contain the information found in the
  2989.  conformance document.
  2990.  
  2991.  
  2992.  1.3.1.3  Conforming Implementation Options
  2993.  
  2994.  The following symbolic constants, described in 2.13.2 reflect
  2995.  implementation options for this standard that could warrant requirement
  2996.  by Conforming POSIX.2 Applications, or in specifications of conforming
  2997.  systems, or both:
  2998.  
  2999.     {POSIX2_SW_DEV}        The system supports the Software Development
  3000.                            Utilities Option in Section 6.
  3001.  
  3002.     {POSIX2_C_BIND}        The system supports the C Language Bindings
  3003.                            Option in Annex B.
  3004.  
  3005.     {POSIX2_C_DEV}         The system supports the C Language Development
  3006.                            Utilities Option in Annex A.
  3007.  
  3008.     {POSIX2_FORT_DEV}      The system supports the FORTRAN Development
  3009.                            Utilities Option in Annex C.
  3010.  
  3011.     {POSIX2_FORT_RUN}      The system supports the FORTRAN Runtime
  3012.                            Utilities Option in Annex C.
  3013.  
  3014.     {POSIX2_LOCALEDEF}     The system supports the creation of locales as
  3015.                            described in 4.35.
  3016.  
  3017.  Additional language bindings and development utility options may be
  3018.  provided in other related standards or in future revisions to this
  3019.  standard.  In the former case, additional symbolic constants of the same
  3020.  general form as shown in this subclause should be defined by the related
  3021.  standard document and made available to the application, without
  3022.  requiring this POSIX.2 document to be updated.
  3023.  
  3024.  
  3025.  
  3026.  
  3027.                Copyright c 1991 IEEE.  All rights reserved.
  3028.       This is an unapproved IEEE Standards Draft, subject to change.
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  16                                                              1 General
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3041.  
  3042.  1.3.2  Application Conformance
  3043.  
  3044.  All applications claiming conformance to this standard fall within one of
  3045.  the following categories:
  3046.  
  3047.  
  3048.  1.3.2.1  Strictly Conforming POSIX.2 Application
  3049.  
  3050.  A Strictly Conforming POSIX.2 Application is an application that requires
  3051.  only the facilities described in this standard (including any required
  3052.  facilities of the underlying operating system; see 2.9.1).  Such an
  3053.  application:
  3054.  
  3055.      (1)  shall accept any implementation behavior that results from
  3056.           actions it takes in areas described in this standard as
  3057.           _i_m_p_l_e_m_e_n_t_a_t_i_o_n-_d_e_f_i_n_e_d or _u_n_s_p_e_c_i_f_i_e_d, or where the standard
  3058.           indicates that implementations may vary;
  3059.  
  3060.      (2)  shall not perform any actions that are described as producing
  3061.           _u_n_d_e_f_i_n_e_d results;
  3062.  
  3063.      (3)  for symbolic constants, shall accept any value in the range
  3064.           permitted by this standard, but shall not rely on any value in
  3065.           the range being greater than the minimums listed in this
  3066.           standard;
  3067.  
  3068.      (4)  shall not use facilities designated as _o_b_s_o_l_e_s_c_e_n_t;
  3069.  
  3070.      (5)  is required to tolerate, and is permitted to adapt to, the        1
  3071.           presence or absence of optional facilities whose availability is  1
  3072.           indicated by the constants in 2.13.1, or that are described       1
  3073.           using the verb _m_a_y.  However, an application requiring a high-    1
  3074.           level language binding option can only be considered at best a
  3075.           Conforming POSIX.2 Application; see 1.3.2.2.
  3076.  
  3077.  Within this standard, any restrictions placed upon a Conforming POSIX.2
  3078.  Application shall also restrict a Strictly Conforming POSIX.2
  3079.  Application.
  3080.  
  3081.  1.3.2.2  Conforming POSIX.2 Application
  3082.  
  3083.  The term Conforming POSIX.2 Application is used to describe either of the
  3084.  two following application types.
  3085.  
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.                Copyright c 1991 IEEE.  All rights reserved.
  3094.       This is an unapproved IEEE Standards Draft, subject to change.
  3095.  
  3096.  
  3097.  
  3098.  
  3099.  
  3100.  1.3 Conformance                                                        17
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3107.  
  3108.  1.3.2.2.1  ISO/IEC Conforming POSIX.2 Application
  3109.  
  3110.  An ISO/IEC Conforming POSIX.2 Application is an application that uses
  3111.  only the facilities described in this standard (including the implied
  3112.  facilities of the underlying operating system; see 2.9.1) and approved
  3113.  conforming language bindings for any ISO/IEC standard.  Such an
  3114.  application shall include a statement of conformance that documents all
  3115.  options and limit dependencies, and all other ISO/IEC standards used.
  3116.  
  3117.  1.3.2.2.2  <National Body> Conforming POSIX.2 Application
  3118.  
  3119.  A <National Body> Conforming POSIX.2 Application differs from an ISO/IEC
  3120.  Conforming POSIX.2 Application in that it also may use specific standards
  3121.  of a single ISO/IEC member body referred to here as ``<_N_a_t_i_o_n_a_l _B_o_d_y>.''
  3122.  Such an application shall include a statement of conformance that
  3123.  documents all options and limit dependencies, and all other <_N_a_t_i_o_n_a_l
  3124.  _B_o_d_y> standards used.
  3125.  
  3126.  
  3127.  1.3.2.3  Conforming POSIX.2 Application Using Extensions
  3128.  
  3129.  A Conforming POSIX.2 Application Using Extensions is an application that
  3130.  differs from a Conforming POSIX.2 Application only in that it uses
  3131.  nonstandard facilities that are consistent with this standard.  Such an
  3132.  application shall fully document its requirements for these extended
  3133.  facilities, in addition to the documentation required of a Conforming
  3134.  POSIX.2 Application.  A Conforming POSIX.2 Application Using Extensions
  3135.  shall be either an ISO/IEC Conforming POSIX.2 Application Using
  3136.  Extensions or a <National Body> Conforming POSIX.2 Application Using
  3137.  Extensions (see 1.3.2.2.1 and 1.3.2.2.2).
  3138.  
  3139.  BEGIN_RATIONALE
  3140.  
  3141.  
  3142.  1.3.3  Conformance Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  3143.  
  3144.  These conformance definitions are closely related to those in
  3145.  POSIX.1 {8}.
  3146.  
  3147.  The terms _C_o_n_f_o_r_m_i_n_g _P_O_S_I_X._2 _A_p_p_l_i_c_a_t_i_o_n and its variants were selected
  3148.  to parallel the terms used in POSIX.1 {8}.
  3149.  
  3150.  The descriptions of the ISO/IEC and <National Body> Conforming POSIX.2
  3151.  Applications are similar to the same descriptions in POSIX.1 {8}.  This
  3152.  is not a duplication of effort, as this standard relies on only a portion
  3153.  of POSIX.1 {8}, as explained in 1.1 and 2.9.1.  Therefore conformance to
  3154.  POSIX.2 has to be described separately from any conformance options or
  3155.  requirements in POSIX.1 {8}.
  3156.  
  3157.  
  3158.  
  3159.                Copyright c 1991 IEEE.  All rights reserved.
  3160.       This is an unapproved IEEE Standards Draft, subject to change.
  3161.  
  3162.  
  3163.  
  3164.  
  3165.  
  3166.  18                                                              1 General
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3173.  
  3174.  A reference to a Language-Independent System Services Option was removed
  3175.  from the list of optional features that may be provided by the conforming
  3176.  implementation.  There is no conformance value provided by that section,
  3177.  except as a reference point for functions actually provided by a real
  3178.  language binding.  Therefore, the language binding sections are the ones
  3179.  that remain in the optional list.  The Draft 8 section Language-Dependent
  3180.  Services for the C Programming Language was removed, as this subject is
  3181.  adequately, and appropriately, covered in Annex A.
  3182.  
  3183.  The documentation requirement for implementation extensions (``shall
  3184.  define an execution environment'') is simply meant to require that
  3185.  system-wide or per-user configuration options or environment variables
  3186.  that affect the operation of applications that use the standard utilities
  3187.  and functions be described in the conformance document.  For example, if
  3188.  setting the (imaginary) LC_TRUTH variable causes changes in the exit
  3189.  status of true, the conformance document must describe this condition and
  3190.  how to avoid it--say, by unsetting the variable in the login script.
  3191.  
  3192.  For further rationale on the types of conformance, see the POSIX.1 {8}
  3193.  Rationale.
  3194.  
  3195.  END_RATIONALE
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.                Copyright c 1991 IEEE.  All rights reserved.
  3226.       This is an unapproved IEEE Standards Draft, subject to change.
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.  1.3 Conformance                                                        19
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242.  
  3243.  
  3244.  
  3245.  
  3246.  
  3247.  
  3248.  
  3249.  
  3250.  
  3251.  
  3252.  
  3253.  
  3254.  
  3255.  
  3256.  
  3257.  
  3258.  
  3259.  
  3260.  
  3261.  
  3262.  
  3263.  
  3264.  
  3265.  
  3266.  
  3267.  
  3268.  
  3269.  
  3270.  
  3271.  
  3272.  
  3273.  
  3274.  
  3275.  
  3276.  
  3277.  
  3278.  
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.  
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.                                                              P1003.2/D11.2
  3305.  
  3306.  
  3307.  
  3308.  
  3309.  
  3310.  
  3311.  
  3312.  
  3313.               Section 2: Terminology and General Requirements
  3314.  
  3315.  
  3316.  
  3317.  2.1  Conventions
  3318.  
  3319.  
  3320.  2.1.1  Editorial Conventions
  3321.  
  3322.  This standard uses the following editorial and typographical conventions.
  3323.  A summary of typographical conventions is shown in Table 2-1.
  3324.  
  3325.  The Bold Courier font is used to show brackets that denote optional
  3326.  arguments in a utility synopsis, as in
  3327.  
  3328.  
  3329.        cut  [-_c _l_i_s_t] [_f_i_l_e__n_a_m_e]
  3330.  
  3331.  These brackets shall not be used by the application unless they are
  3332.  specifically mentioned as literal input characters by the utility
  3333.  description.
  3334.  
  3335.  There are two types of symbols enclosed in angle brackets (< >):
  3336.  
  3337.     C-Language Headers   The header name is in the Courier font, such as
  3338.                          <sys/stat.h>.  When coding C programs, the
  3339.                          brackets are used as required by the language.
  3340.  
  3341.     Parameters           Parameters, also called _m_e_t_a_v_a_r_i_a_b_l_e_s, are in
  3342.                          italics, such as <_d_i_r_e_c_t_o_r_y _p_a_t_h_n_a_m_e>.  The
  3343.                          entire symbol, including the brackets, is meant
  3344.                          to be replaced by the value of the symbol
  3345.                          described within the brackets.
  3346.  
  3347.  Numbers within braces, such as ``POSIX.1 {8},'' represent cross
  3348.  references to the Normative References clause (see 1.2).  If the number
  3349.  is preceded by a B, it represents a Bibliographic entry (see Annex D).
  3350.  Bibliographic entries are for information only.
  3351.  
  3352.  In some examples, the Bold Courier font is used to indicate the system's
  3353.  output that resulted from some user input, shown in Courier.
  3354.  
  3355.  
  3356.  
  3357.                Copyright c 1991 IEEE.  All rights reserved.
  3358.       This is an unapproved IEEE Standards Draft, subject to change.
  3359.  
  3360.  
  3361.  
  3362.  
  3363.  
  3364.  2.1 Conventions                                                        21
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3371.  
  3372.  
  3373.                   Table 2-1  -  Typographical Conventions
  3374.  __________________________________________________________________________________________________________________________________________________
  3375.                  Reference                           Example
  3376.     ___________________________________________________________________
  3377.  
  3378.     C-Language Data Type                  _l_o_n_g
  3379.     C-Language Function                   _s_y_s_t_e_m()
  3380.     C-Language Function Argument          _a_r_g_1
  3381.     C-Language Global External            _e_r_r_n_o
  3382.     C-Language Header                     <sys/stat.h>
  3383.     C-Language Keyword                    #define
  3384.     Cross Reference: Annex                Annex A
  3385.     Cross Reference: Clause               2.3
  3386.     Cross Reference: Other Standard       ISO 9999-1 {_n}
  3387.     Cross Reference: Section              Section 2
  3388.     Cross Reference: Subclause            2.3.4, 2.3.4.5, 2.3.4.5.6
  3389.     Defined Term                          (see text)
  3390.     Environment Variable                  PATH
  3391.     Error Number                          [EINTR]
  3392.     Example Input                         echo foo
  3393.     Example Output                        foo
  3394.     Figure Reference                      Figure 7
  3395.     File Name                             /tmp
  3396.     Parameter                             <_d_i_r_e_c_t_o_r_y _p_a_t_h_n_a_m_e>
  3397.     Special Character                     <newline>
  3398.     Symbolic Constant, Limit              {_POSIX_VDISABLE}, {LINE_MAX}
  3399.     Table Reference                       Table 6
  3400.     Utility Name                          awk
  3401.     Utility Operand                       _f_i_l_e__n_a_m_e
  3402.     Utility Option                        -c
  3403.     Utility Option with Option-Argument   -w _w_i_d_t_h
  3404.  __________________________________________________________________________________________________________________________________________________
  3405.  
  3406.  
  3407.  Defined terms are shown in three styles, depending on context:
  3408.  
  3409.      (1)  Terms defined in 2.2.1, 2.2.2, and 3.1 are expressed as
  3410.           subclause titles.  Alternative forms of the terms appear in
  3411.           [brackets].
  3412.  
  3413.      (2)  The initial appearances of other terms, applying to a limited
  3414.           portion of the text, are in _i_t_a_l_i_c_s.
  3415.  
  3416.      (3)  Subsequent appearances of the term are in the Roman font.
  3417.  
  3418.  Symbolic constants are shown in two styles:  those within curly braces
  3419.  are intended to call the reader's attention to values in <limits.h> and
  3420.  <unistd.h>; those without braces are usually defined by one or a few
  3421.  related functions.  There is no semantic difference between these two
  3422.  
  3423.                Copyright c 1991 IEEE.  All rights reserved.
  3424.       This is an unapproved IEEE Standards Draft, subject to change.
  3425.  
  3426.  
  3427.  
  3428.  
  3429.  
  3430.  22                                 2 Terminology and General Requirements
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3437.  
  3438.  forms of presentation.
  3439.  
  3440.  Filenames and pathnames are shown in Courier.  When a pathname is shown
  3441.  starting with ``$HOME/'', this indicates the remaining components of the
  3442.  pathname are to be related to the directory named by the user's HOME
  3443.  environment variable.
  3444.  
  3445.  The style selected for some of the special characters, such as <newline>,
  3446.  matches the form of the input given to the localedef utility (see 2.5.2).
  3447.  Generally, the characters selected for this special treatment are those
  3448.  that are not visually distinct, such as the control characters <tab> or
  3449.  <newline>.
  3450.  
  3451.  Literal characters and strings used as input or output are shown in
  3452.  various ways, depending on context:
  3453.  
  3454.     %,  begin   When no confusion would result, the character or string is
  3455.                 rendered in the Courier font and used directly in the
  3456.                 text.
  3457.  
  3458.     'c'         In some cases a character is enclosed in single-quote
  3459.                 characters, similar to a C-language character constant.
  3460.                 Unless otherwise noted, the quotes shall not be used as
  3461.                 input or output.
  3462.  
  3463.     "string"    In some cases, a string is enclosed in double-quote
  3464.                 characters, similar to a C-language string constant.
  3465.                 Unless otherwise noted, the quotes shall not be used as
  3466.                 input or output.
  3467.  
  3468.  Defined names that are usually in lowercase, particularly function names,
  3469.  are never used at the beginning of a sentence or anywhere else that
  3470.  regular English usage would require them to be capitalized.
  3471.  
  3472.  Parenthetical expressions within normative text also contain normative
  3473.  information.  The general typographic hierarchy of parenthetical
  3474.  expressions is:
  3475.  
  3476.        {     [     (     )     ]     }
  3477.  
  3478.  The square brackets are most frequently used to enclose a parenthetical
  3479.  expression that contains a function name [such as _w_a_i_t_p_i_d()], with its
  3480.  built-in parentheses.
  3481.  
  3482.  In some cases, tabular information is presented inline; in others it is
  3483.  presented in a separately-labeled Table.  This arrangement was employed
  3484.  purely for ease of reference and there is no normative difference between
  3485.  these two cases.
  3486.  
  3487.  
  3488.  
  3489.                Copyright c 1991 IEEE.  All rights reserved.
  3490.       This is an unapproved IEEE Standards Draft, subject to change.
  3491.  
  3492.  
  3493.  
  3494.  
  3495.  
  3496.  2.1 Conventions                                                        23
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3503.  
  3504.  Annexes marked as _n_o_r_m_a_t_i_v_e are parts of the standard that pose
  3505.  requirements, exactly the same as the numbered Sections, but have been
  3506.  moved to near the end of the document for clarity of exposition.
  3507.  _I_n_f_o_r_m_a_t_i_v_e Annexes are for information only and pose no requirements.
  3508.  All material preceding page 1 of the document (the ``front matter'') and
  3509.  the two indexes at the end are also only informative.
  3510.  
  3511.  NOTES that appear in a smaller point size and are indented have one of
  3512.  two different meanings, depending on their location:
  3513.  
  3514.      - When they are within the normal text of the document, they are the
  3515.        same as footnotes--informative, posing no requirements on
  3516.        implementations or applications.
  3517.  
  3518.      - When they are attached to Tables or Figures, they are normative,
  3519.        posing requirements.
  3520.  
  3521.  Text marked as examples (including the use of ``e.g.'')  is for
  3522.  information only.  The exception to this comes in the C-language programs
  3523.  and program fragments used to represent algorithms, as described in
  3524.  2.1.3.
  3525.  
  3526.  The typographical conventions listed here are for ease of reading only.
  3527.  Editorial inconsistencies in the use of typography are unintentional and
  3528.  have no normative meaning in this standard.
  3529.  
  3530.  
  3531.  2.1.2  Grammar Conventions
  3532.  
  3533.  Portions of this standard are expressed in terms of a special grammar
  3534.  notation.  It is used to portray the complex syntax of certain program
  3535.  input.  The grammar is based on the syntax used by the yacc utility (see
  3536.  A.3).  However, it does not represent fully functional yacc input,
  3537.  suitable for program use:  the lexical processing and all semantic
  3538.  requirements are described only in textual form.  The grammar is not
  3539.  based on source used in any traditional implementation and has not been
  3540.  tested with the semantic code that would normally be required to
  3541.  accompany it.  Furthermore, there is no implication that the partial yacc
  3542.  code presented represents the most efficient, or only, means of
  3543.  supporting the complex syntax within the utility.  Implementations may
  3544.  use other programming languages or algorithms, as long as the syntax
  3545.  supported is the same as that represented by the grammar.
  3546.  
  3547.  The following typographical conventions are used in the grammar; they
  3548.  have no significance except to aid in reading.
  3549.  
  3550.      - The identifiers for the reserved words of the language are shown
  3551.        with a leading capital letter.  (These are terminals in the
  3552.        grammar.  Examples:  While, Case.)
  3553.  
  3554.  
  3555.                Copyright c 1991 IEEE.  All rights reserved.
  3556.       This is an unapproved IEEE Standards Draft, subject to change.
  3557.  
  3558.  
  3559.  
  3560.  
  3561.  
  3562.  24                                 2 Terminology and General Requirements
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3569.  
  3570.      - The identifiers for terminals in the grammar are all named with      1
  3571.        uppercase letters and underscores.  Examples:  NEWLINE, ASSIGN_OP,   1
  3572.        NAME.                                                                1
  3573.  
  3574.      - The identifiers for nonterminals are all lowercase.
  3575.  
  3576.  
  3577.  2.1.3  Miscellaneous Conventions
  3578.  
  3579.  This standard frequently uses the C language to express algorithms in
  3580.  terms of programs or program fragments.  The following shall be
  3581.  considered in reading this code:
  3582.  
  3583.      - The programs use the syntax and semantics described by the
  3584.        C Standard {7}.
  3585.  
  3586.      - The programs are merely examples and do not represent the most
  3587.        efficient, or only, means of coding the interface.  Implementations
  3588.        may use other programming languages or algorithms, as long as the
  3589.        results are the same as those achieved by the programs in this
  3590.        standard.
  3591.  
  3592.      - C-language comments are informative and pose no requirements.
  3593.  
  3594.  Further conventions are presented in:
  3595.  
  3596.      - Utility Conventions, 2.10, describing utility and application
  3597.        command-line syntax
  3598.  
  3599.      - File Format Notation, 2.12, describing the notation used to
  3600.        represent utility input and output
  3601.  
  3602.  
  3603.  2.1.4  Conventions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  3604.  
  3605.  The C language was chosen for many examples because:
  3606.  
  3607.      - It eliminates any requirement to document a different pseudocode.
  3608.  
  3609.      - It is a familiar language to many of the potential readers of
  3610.        POSIX.2.
  3611.  
  3612.      - It is the language most widely used for historical implementations
  3613.        of the utilities.
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.                Copyright c 1991 IEEE.  All rights reserved.
  3622.       This is an unapproved IEEE Standards Draft, subject to change.
  3623.  
  3624.  
  3625.  
  3626.  
  3627.  
  3628.  2.1 Conventions                                                        25
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3635.  
  3636.  2.2  Definitions
  3637.  
  3638.  
  3639.  2.2.1  Terminology
  3640.  
  3641.  For the purposes of this standard, the following definitions apply:
  3642.  
  3643.  
  3644.  2.2.1.1  can:  The word _c_a_n is to be interpreted as describing a
  3645.  permissible optional feature or behavior available to the application;
  3646.  the implementation shall support such features or behaviors as mandatory
  3647.  requirements.
  3648.  
  3649.  2.2.1.2  conformance document:  A document provided by an implementor
  3650.  that contains implementation details as described in 1.3.1.2.
  3651.  
  3652.  
  3653.  2.2.1.3  implementation:  An object providing to applications and users
  3654.  the services defined by this standard.  The word _i_m_p_l_e_m_e_n_t_a_t_i_o_n is to be
  3655.  interpreted to mean that object, after it has been modified in accordance
  3656.  with the manufacturer's instructions to:
  3657.  
  3658.      - configure it for conformance with this standard;
  3659.  
  3660.      - select some of the various optional facilities described by this
  3661.        standard, through customization by local system administrators or
  3662.        operators.
  3663.  
  3664.  An exception to this meaning occurs when discussing conformance
  3665.  documentation or using the term _i_m_p_l_e_m_e_n_t_a_t_i_o_n _d_e_f_i_n_e_d.  See 2.2.1.4 and
  3666.  1.3.1.2.
  3667.  
  3668.  2.2.1.4  implementation defined:  When a value or behavior is described
  3669.  by this standard as _i_m_p_l_e_m_e_n_t_a_t_i_o_n _d_e_f_i_n_e_d, the implementation provider
  3670.  shall document the requirements for correct program construction and
  3671.  correct data in the use of that value or behavior.  When the value or
  3672.  behavior in the implementation is designed to be variable or customizable
  3673.  on each instantiation of the system, the implementation provider shall
  3674.  document the nature and permissible ranges of this variation.  (See
  3675.  1.3.1.2.)
  3676.  
  3677.  
  3678.  2.2.1.5  may:  The word _m_a_y is to be interpreted as describing an
  3679.  optional feature or behavior of the implementation that is not required
  3680.  by this standard, but there is no prohibition against providing it.  A     1
  3681.  Strictly Conforming POSIX.2 Application is permitted to use such           1
  3682.  features, but shall not rely on the implementation's actions in such       1
  3683.  cases.  To avoid ambiguity, the reverse sense of _m_a_y is not expressed as   1
  3684.  _m_a_y _n_o_t, but as _n_e_e_d _n_o_t.
  3685.  
  3686.  
  3687.                Copyright c 1991 IEEE.  All rights reserved.
  3688.       This is an unapproved IEEE Standards Draft, subject to change.
  3689.  
  3690.  
  3691.  
  3692.  
  3693.  
  3694.  26                                 2 Terminology and General Requirements
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3701.  
  3702.  2.2.1.6  obsolescent:  Certain features are _o_b_s_o_l_e_s_c_e_n_t, which means that
  3703.  they may be considered for withdrawal in future revisions of this
  3704.  standard.  They are retained in this version because of their widespread
  3705.  use.  Their use in new applications is discouraged.
  3706.  
  3707.  
  3708.  2.2.1.7  shall:  In this standard, the word _s_h_a_l_l is to be interpreted as
  3709.  a requirement on the implementation or on Strictly Conforming POSIX.2
  3710.  Applications, where appropriate.
  3711.  
  3712.  2.2.1.8  should:  With respect to implementations, the word _s_h_o_u_l_d is to
  3713.  be interpreted as an implementation recommendation, but not a
  3714.  requirement.  With respect to applications, the word _s_h_o_u_l_d is to be
  3715.  interpreted as recommended programming practice for applications and a
  3716.  requirement for Strictly Conforming POSIX.2 Applications.
  3717.  
  3718.  
  3719.  2.2.1.9  system documentation:  All documentation provided with an
  3720.  implementation, except the conformance document.  Electronically
  3721.  distributed documents for an implementation are considered part of the
  3722.  system documentation.
  3723.  
  3724.  2.2.1.10  undefined:  A value or behavior is _u_n_d_e_f_i_n_e_d if the standard
  3725.  imposes no portability requirements on applications for erroneous program
  3726.  construction, erroneous data, or use of an indeterminate value.
  3727.  Implementations (or other standards) may specify the result of using that
  3728.  value or causing that behavior.  An application using such behaviors is
  3729.  using extensions, as defined in 1.3.2.3.
  3730.  
  3731.  
  3732.  2.2.1.11  unspecified:  A value or behavior is _u_n_s_p_e_c_i_f_i_e_d if the
  3733.  standard imposes no portability requirements on applications for a
  3734.  correct program construction or correct data.  Implementations (or other
  3735.  standards) may specify the result of using that value or causing that
  3736.  behavior.  An application requiring a specific behavior, rather than
  3737.  tolerating any behavior when using that functionality, is using
  3738.  extensions, as defined in 1.3.2.3.
  3739.  
  3740.  BEGIN_RATIONALE
  3741.  
  3742.  2.2.1.12  Terminology Rationale (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  3743.  
  3744.  Most of these terms were adapted from their POSIX.1 {8} counterparts with
  3745.  little modification.
  3746.  
  3747.  The reader is referred to the definition of _p_r_o_g_r_a_m in 2.2.2.119 to
  3748.  understand the expression ``program construction.''  The use of _p_r_o_g_r_a_m
  3749.  in this standard is differentiated from POSIX.1 {8}'s emphasis only on
  3750.  high level languages by this standard's broader concern with utility and
  3751.  
  3752.  
  3753.                Copyright c 1991 IEEE.  All rights reserved.
  3754.       This is an unapproved IEEE Standards Draft, subject to change.
  3755.  
  3756.  
  3757.  
  3758.  
  3759.  
  3760.  2.2 Definitions                                                        27
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3767.  
  3768.  command language interactions.  Included in the scope of program
  3769.  construction are:
  3770.  
  3771.      (1)  Shell command language
  3772.  
  3773.      (2)  Command arguments
  3774.  
  3775.      (3)  Regular expressions, of various types
  3776.  
  3777.      (4)  Command input language syntax, such as awk, bc, ed, lex, make,
  3778.           sed, and yacc.  Some of these are so complex that they rival
  3779.           traditional high level languages.
  3780.  
  3781.  The usage of _c_a_n and _m_a_y were selected to contrast optional application
  3782.  behavior (can) against optional implementation behavior (may).
  3783.  
  3784.  The term _s_u_p_p_o_r_t_e_d was removed from Draft 8; it had originally been
  3785.  copied from the POSIX.1 {8} document, but it later became clear that its
  3786.  requirement for function ``stubs'' for unsupported functions made little
  3787.  sense in this standard.  The term _s_u_p_p_o_r_t therefore reverts to its
  3788.  English-language meaning.
  3789.  
  3790.  The term _o_b_s_o_l_e_s_c_e_n_t was changed to _d_e_p_r_e_c_a_t_e_d in some earlier drafts,
  3791.  but it was restored to match POSIX.1 {8}'s use of the term.  It means
  3792.  ``do not use this feature in new applications.''  The obsolescence
  3793.  concept is not an ideal solution, but was used as a method of increasing
  3794.  consensus:  many more objections would be heard from the user community
  3795.  if some of these historical features were suddenly withdrawn without the
  3796.  grace period obsolescence implies.  The phrase ``may be considered for
  3797.  withdrawal in future revisions'' implies that the result of that
  3798.  consideration might in fact keep those features indefinitely if the
  3799.  predominance of applications does not migrate away from them quickly.
  3800.  
  3801.  END_RATIONALE
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.                Copyright c 1991 IEEE.  All rights reserved.
  3820.       This is an unapproved IEEE Standards Draft, subject to change.
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.  28                                 2 Terminology and General Requirements
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3833.  
  3834.  2.2.2  General Terms
  3835.  
  3836.  For the purposes of this standard, the following definitions apply.
  3837.  
  3838.  
  3839.  2.2.2.1  absolute pathname:  See _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.
  3840.  
  3841.  2.2.2.2  address space:  The memory locations that can be referenced by a
  3842.  process.  [POSIX.1 {8}]
  3843.  
  3844.  
  3845.  2.2.2.3  affirmative response:  An input string that matches one of the
  3846.  responses acceptable to the LC_MESSAGES category keyword yesexpr,
  3847.  matching an extended regular expression in the current locale; see 2.5.
  3848.  
  3849.  2.2.2.4  <alert>:  A character that in the output stream shall indicate    1
  3850.  that a terminal should alert its user via a visual or audible              1
  3851.  notification.
  3852.  
  3853.  The <alert> shall be the character designated by '\a' in the C language
  3854.  binding.  It is unspecified whether this character is the exact sequence
  3855.  transmitted to an output device by the system to accomplish the alert
  3856.  function.
  3857.  
  3858.  
  3859.  2.2.2.5  angle brackets:  The characters ``<'' (_l_e_f_t-_a_n_g_l_e-_b_r_a_c_k_e_t) and
  3860.  ``>'' (_r_i_g_h_t-_a_n_g_l_e-_b_r_a_c_k_e_t).
  3861.  
  3862.  When used in the phrase ``enclosed in angle brackets'' the symbol ``<''
  3863.  shall immediately precede the object to be enclosed, and ``>'' shall
  3864.  immediately follow it.  When describing these characters in 2.4, the
  3865.  names <less-than-sign> and <greater-than-sign> are used.
  3866.  
  3867.  2.2.2.6  appropriate privileges:  An implementation-defined means of
  3868.  associating privileges with a process with regard to the function calls
  3869.  and function call options defined in POSIX.1 {8} that need special
  3870.  privileges.
  3871.  
  3872.  There may be zero or more such means.  [POSIX.1 {8}]
  3873.  
  3874.  
  3875.  2.2.2.7  argument:  A parameter passed to a utility as the equivalent of
  3876.  a single string in the _a_r_g_v array created by one of the POSIX.1 {8} _e_x_e_c
  3877.  functions.
  3878.  
  3879.  See 2.10.1 and 3.9.1.1.  An argument is one of the options, option-
  3880.  arguments, or operands following the command name.
  3881.  
  3882.  
  3883.  
  3884.  
  3885.                Copyright c 1991 IEEE.  All rights reserved.
  3886.       This is an unapproved IEEE Standards Draft, subject to change.
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  2.2 Definitions                                                        29
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  3899.  
  3900.  2.2.2.8  asterisk:  The character ``*''.
  3901.  
  3902.  
  3903.  2.2.2.9  background process:  A process that is a member of a background
  3904.  process group.  [POSIX.1 {8}]
  3905.  
  3906.  2.2.2.10  background process group:  Any process group, other than a
  3907.  foreground process group, that is a member of a session that has
  3908.  established a connection with a controlling terminal.  [POSIX.1 {8}]
  3909.  
  3910.  
  3911.  2.2.2.11  backquote:  The character ```'', also known as a _g_r_a_v_e _a_c_c_e_n_t.
  3912.  
  3913.  2.2.2.12  backslash:  The character ``\'', also known as a _r_e_v_e_r_s_e
  3914.  _s_o_l_i_d_u_s.
  3915.  
  3916.  
  3917.  2.2.2.13  <backspace>:  A character that normally causes printing (or
  3918.  displaying) to occur one column position previous to the position about
  3919.  to be printed.
  3920.  
  3921.  The <backspace> shall be the character designated by '\b' in the C
  3922.  language binding.  It is unspecified whether this character is the exact
  3923.  sequence transmitted to an output device by the system to accomplish the
  3924.  backspace function.  The <backspace> character defined here is not
  3925.  necessarily the ERASE special character defined in POSIX.1 {8} 7.1.1.9.
  3926.  
  3927.  2.2.2.14  basename:  The final, or only, filename in a pathname.
  3928.  
  3929.  
  3930.  2.2.2.15  basic regular expression:  A pattern (sequence of characters or
  3931.  symbols) constructed according to the rules defined in 2.8.3.
  3932.  
  3933.  2.2.2.16  <blank>:  One of the characters that belong to the blank
  3934.  character class as defined via the LC_CTYPE category in the current
  3935.  locale.
  3936.  
  3937.  In the POSIX Locale, a <blank> is either a <tab> or a <space>.
  3938.  
  3939.  
  3940.  2.2.2.17  blank line:  A line consisting solely of zero or more <blank>s
  3941.  terminated by a <newline>.
  3942.  
  3943.  See also _e_m_p_t_y _l_i_n_e (2.2.2.44).
  3944.  
  3945.  2.2.2.18  block special file:  A file that refers to a device.
  3946.  
  3947.  A block special file is normally distinguished from a character special
  3948.  file by providing access to the device in a manner such that the hardware
  3949.  
  3950.  
  3951.                Copyright c 1991 IEEE.  All rights reserved.
  3952.       This is an unapproved IEEE Standards Draft, subject to change.
  3953.  
  3954.  
  3955.  
  3956.  
  3957.  
  3958.  30                                 2 Terminology and General Requirements
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  3965.  
  3966.  characteristics of the device are not visible.  [POSIX.1 {8}]
  3967.  
  3968.  
  3969.  2.2.2.19  braces:  The characters ``{'' (_l_e_f_t _b_r_a_c_e) and ``}'' (_r_i_g_h_t
  3970.  _b_r_a_c_e), also known as _c_u_r_l_y _b_r_a_c_e_s.
  3971.  
  3972.  When used in the phrase ``enclosed in (curly) braces'' the symbol ``{''
  3973.  shall immediately precede the object to be enclosed, and ``}'' shall
  3974.  immediately follow it.  When describing these characters in 2.4, the
  3975.  names <left-brace> and <right-brace> are used.
  3976.  
  3977.  2.2.2.20  brackets:  The characters ``['' (_l_e_f_t-_b_r_a_c_k_e_t) and ``]''
  3978.  (_r_i_g_h_t-_b_r_a_c_k_e_t), also known as _s_q_u_a_r_e _b_r_a_c_k_e_t_s.
  3979.  
  3980.  When used in the phrase ``enclosed in (square) brackets'' the symbol
  3981.  ``['' shall immediately precede the object to be enclosed, and ``]''
  3982.  shall immediately follow it.  When describing these characters in 2.4,
  3983.  the names <left-square-bracket> and <right-square-bracket> are used.
  3984.  
  3985.  
  3986.  2.2.2.21  built-in utility:  A utility implemented within a shell.
  3987.  
  3988.  The utilities referred to as _s_p_e_c_i_a_l _b_u_i_l_t-_i_n_s have special qualities,
  3989.  described in 3.14.  Unless qualified, the term _b_u_i_l_t-_i_n includes the
  3990.  special built-in utilities.
  3991.  
  3992.  The utilities referred to as _r_e_g_u_l_a_r _b_u_i_l_t-_i_n_s are those named in
  3993.  Table 2-2.  As indicated in 2.3, there is no requirement that these
  3994.  utilities be actually built into the shell on the implementation, but
  3995.  that they do have special command-search qualities.
  3996.  
  3997.  2.2.2.22  byte:  An individually addressable unit of data storage that is  1
  3998.  equal to or larger than an octet, used to store a character or a portion   1
  3999.  of a character; see 2.2.2.24.                                              1
  4000.  
  4001.  A byte is composed of a contiguous sequence of bits, the number of which   1
  4002.  is implementation defined.  The least significant bit is called the _l_o_w-
  4003.  _o_r_d_e_r bit; the most significant is called the _h_i_g_h-_o_r_d_e_r bit.
  4004.  [POSIX.1 {8}]
  4005.  
  4006.  NOTE:  This definition of _b_y_t_e is actually from the C Standard {7}
  4007.  because POSIX.1 {8} merely references it without copying the text.  It     1
  4008.  has been reworded slightly to clarify its intent without introducing the   1
  4009.  C Standard {7} terminology ``basic execution character set,'' which is     1
  4010.  inapplicable to this standard.  It deviates intentionally from the usage   1
  4011.  of _b_y_t_e in some other standards, where it is used as a synonym for _o_c_t_e_t   1
  4012.  (always eight bits).  On a POSIX.1 {8} system, a byte may be larger than   1
  4013.  eight bits so that it can be an integral portion of larger data objects    1
  4014.  that are not evenly divisible by eight bits (such as a 36-bit word that    1
  4015.  contains 4 9-bit bytes).                                                   1
  4016.  
  4017.                Copyright c 1991 IEEE.  All rights reserved.
  4018.       This is an unapproved IEEE Standards Draft, subject to change.
  4019.  
  4020.  
  4021.  
  4022.  
  4023.  
  4024.  2.2 Definitions                                                        31
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4031.  
  4032.  2.2.2.23  <carriage-return>:  A character that in the output stream shall  1
  4033.  indicate that printing should start at the beginning of the same physical
  4034.  line in which the <carriage-return> occurred.
  4035.  
  4036.  The <carriage-return> shall be the character designated by '\r' in the C
  4037.  language binding.  It is unspecified whether this character is the exact
  4038.  sequence transmitted to an output device by the system to accomplish the
  4039.  movement to the beginning of the line.
  4040.  
  4041.  
  4042.  2.2.2.24  character:  A sequence of one or more bytes representing a
  4043.  single graphic symbol.
  4044.  NOTE:  This term corresponds in the C Standard {7} to the term _m_u_l_t_i_b_y_t_e
  4045.  _c_h_a_r_a_c_t_e_r, noting that a single-byte character is a special case of
  4046.  multibyte character.  Unlike the usage in the C Standard {7}, _c_h_a_r_a_c_t_e_r
  4047.  here has no necessary relationship with storage space, and _b_y_t_e is used
  4048.  when storage space is discussed.
  4049.  
  4050.  [POSIX.1 {8}]
  4051.  
  4052.  (See 2.4 for a further explanation of the graphical representations of
  4053.  characters, or ``glyphs,'' versus character encodings.)
  4054.  
  4055.  2.2.2.25  character class:  A named set of characters sharing an
  4056.  attribute associated with the name of the class.
  4057.  
  4058.  The classes and the characters that they contain are dependent on the
  4059.  value of the LC_CTYPE category in the current locale; see 2.5.
  4060.  
  4061.  
  4062.  2.2.2.26  character special file:  A file that refers to a device.
  4063.  
  4064.  One specific type of character special file is a terminal device file,
  4065.  whose access is defined in POSIX.1 {8} section 7.1.  Other character
  4066.  special files have no structure defined by this standard, and their use
  4067.  is unspecified by this standard.  [POSIX.1 {8}]
  4068.  
  4069.  2.2.2.27  circumflex:  The character ``^''.
  4070.  
  4071.  
  4072.  2.2.2.28  collating element:  The smallest entity used to determine the
  4073.  logical ordering of strings.
  4074.  
  4075.  See _c_o_l_l_a_t_i_o_n _s_e_q_u_e_n_c_e (2.2.2.30).  A collating element shall consist of
  4076.  either a single character, or two or more characters collating as a
  4077.  single entity.  The value of the LC_COLLATE category in the current
  4078.  locale determines the current set of collating elements.
  4079.  
  4080.  
  4081.  
  4082.  
  4083.                Copyright c 1991 IEEE.  All rights reserved.
  4084.       This is an unapproved IEEE Standards Draft, subject to change.
  4085.  
  4086.  
  4087.  
  4088.  
  4089.  
  4090.  32                                 2 Terminology and General Requirements
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4097.  
  4098.  2.2.2.29  collation:  The logical ordering of strings according to
  4099.  defined precedence rules.
  4100.  
  4101.  These rules identify a collation sequence between the collating elements,
  4102.  and such additional rules that can be used to order strings consisting of
  4103.  multiple collating elements.
  4104.  
  4105.  
  4106.  2.2.2.30  collation sequence:  The relative order of collating elements
  4107.  as determined by the setting of the LC_COLLATE category in the current
  4108.  locale.
  4109.  
  4110.  The character order, as defined for the LC_COLLATE category in the         2
  4111.  current locale (see 2.5.2.2), defines the relative order of all collating  2
  4112.  elements, such that each element occupies a unique position in the order.  2
  4113.  In addition, one or more collation weights can be assigned for each        2
  4114.  collating element; these weights are used to determine the relative order  2
  4115.  of strings in, e.g., the sort utility.                                     2
  4116.  
  4117.  Multilevel sorting is accomplished by assigning elements one or more
  4118.  collation weights, up to the limit {COLL_WEIGHTS_MAX}.  On each level,
  4119.  elements may be given the same weight (at the primary level, called an     1
  4120.  _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s; see 2.2.2.47) or be omitted from the sequence.
  4121.  Strings that collate equal using the first assigned weight (primary
  4122.  ordering), are then compared using the next assigned weight (secondary
  4123.  ordering), and so on.
  4124.  
  4125.  2.2.2.31  column position:  A unit of horizontal measure related to
  4126.  characters in a line.                                                      2
  4127.  
  4128.  It is assumed that each character in a character set has an intrinsic      2
  4129.  column width independent of any output device.  Each printable character   2
  4130.  in the portable character set has a column width of one.  The standard     2
  4131.  utilities, when used as described in this standard, assume that all        2
  4132.  characters have integral column widths.  The column width of a character   2
  4133.  is not necessarily related to the internal representation of the           2
  4134.  character (numbers of bits or octets).                                     2
  4135.  
  4136.  The column position of a character in a line is defined as one plus the    2
  4137.  sum of the column widths of the preceding characters in the line.  Column  2
  4138.  positions are numbered starting from 1.
  4139.  
  4140.  
  4141.  2.2.2.32  command:  A directive to the shell to perform a particular
  4142.  task; see 3.9.
  4143.  
  4144.  2.2.2.33  current working directory:  See _w_o_r_k_i_n_g _d_i_r_e_c_t_o_r_y in 2.2.2.159.
  4145.  
  4146.  
  4147.  
  4148.  
  4149.                Copyright c 1991 IEEE.  All rights reserved.
  4150.       This is an unapproved IEEE Standards Draft, subject to change.
  4151.  
  4152.  
  4153.  
  4154.  
  4155.  
  4156.  2.2 Definitions                                                        33
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4163.  
  4164.  2.2.2.34  command language interpreter:  See 2.2.2.133.
  4165.  
  4166.  
  4167.  2.2.2.35  directory:  A file that contains directory entries.
  4168.  
  4169.  No two directory entries in the same directory shall have the same name.
  4170.  [POSIX.1 {8}]
  4171.  
  4172.  2.2.2.36  directory entry [link]:  An object that associates a filename
  4173.  with a file.
  4174.  
  4175.  Several directory entries can associate names with the same file.
  4176.  [POSIX.1 {8}]
  4177.  
  4178.  
  4179.  2.2.2.37  dollar-sign:  The character ``$''.
  4180.  
  4181.  This standard permits the substitution of the ``currency symbol'' graphic
  4182.  defined in ISO/IEC 646 {1} for this symbol when the character set being
  4183.  used has substituted that graphic for the graphic $.  The graphic symbol
  4184.  $ is always used in this standard, but not in any monetary sense.
  4185.  
  4186.  2.2.2.38  dot:  The filename consisting of a single dot character (.).
  4187.  
  4188.  See _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.  [POSIX.1 {8}]
  4189.  
  4190.  In the context of shell special built-in utilities, see 3.14.4.
  4191.  
  4192.  
  4193.  2.2.2.39  dot-dot:  The filename consisting solely of two dot characters
  4194.  (..).
  4195.  
  4196.  See _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.  [POSIX.1 {8}]
  4197.  
  4198.  2.2.2.40  double-quote:  The character ``"'', also known as _q_u_o_t_a_t_i_o_n-
  4199.  _m_a_r_k.
  4200.  
  4201.  
  4202.  2.2.2.41  effective group ID:  An attribute of a process that is used in
  4203.  determining various permissions, including file access permissions,
  4204.  described in 2.2.2.55.
  4205.  
  4206.  See _g_r_o_u_p _I_D.  This value is subject to change during the process
  4207.  lifetime, as described in POSIX.1 {8} 3.1.2 (_e_x_e_c) and 4.2.2 [_s_e_t_g_i_d()].
  4208.  [POSIX.1 {8}]
  4209.  
  4210.  2.2.2.42  effective user ID:  An attribute of a process that is used in
  4211.  determining various permissions, including file access permissions.
  4212.  
  4213.  
  4214.  
  4215.                Copyright c 1991 IEEE.  All rights reserved.
  4216.       This is an unapproved IEEE Standards Draft, subject to change.
  4217.  
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  34                                 2 Terminology and General Requirements
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4229.  
  4230.  See _u_s_e_r _I_D.  This value is subject to change during the process
  4231.  lifetime, as described in POSIX.1 {8} 3.1.2 (_e_x_e_c) and 4.2.2 [_s_e_t_u_i_d()].
  4232.  [POSIX.1 {8}]
  4233.  
  4234.  
  4235.  2.2.2.43  empty directory:  A directory that contains, at most, directory
  4236.  entries for dot and dot-dot.  [POSIX.1 {8}]
  4237.  
  4238.  2.2.2.44  empty line:  A line consisting of only a <newline> character.
  4239.  
  4240.  See also _b_l_a_n_k _l_i_n_e (2.2.2.17).
  4241.  
  4242.  
  4243.  2.2.2.45  empty string [null string]:  A character array whose first
  4244.  element is a null character.  [POSIX.1 {8}]
  4245.  
  4246.  2.2.2.46  Epoch:  The time 0 hours, 0 minutes, 0 seconds, January 1,
  4247.  1970, Coordinated Universal Time.
  4248.  
  4249.  See _s_e_c_o_n_d_s _s_i_n_c_e _t_h_e _E_p_o_c_h.  [POSIX.1 {8}]
  4250.  
  4251.  
  4252.  2.2.2.47  equivalence class:  A set of collating elements with the same    1
  4253.  primary collation weight.                                                  1
  4254.  
  4255.  Elements in an equivalence class are typically elements that naturally
  4256.  group together, such as all accented letters based on the same base
  4257.  letter.
  4258.  
  4259.  The collation order of elements within an equivalence class is determined  1
  4260.  by the weights assigned on any subsequent levels after the primary         1
  4261.  weight.                                                                    1
  4262.  
  4263.  2.2.2.48  executable file:  A regular file acceptable as a new process
  4264.  image file by the equivalent of the POSIX.1 {8} _e_x_e_c family of functions,
  4265.  and thus usable as one form of a utility.
  4266.  
  4267.  See _e_x_e_c in POSIX.1 {8} 3.1.2.  The standard utilities described as
  4268.  compilers can produce executable files, but other unspecified methods of
  4269.  producing executable files may also be provided.  The internal format of
  4270.  an executable file is unspecified, but a conforming application shall not
  4271.  assume an executable file is a text file.
  4272.  
  4273.  
  4274.  2.2.2.49  execute:  To perform the actions described in 3.9.1.1.
  4275.  
  4276.  See also _i_n_v_o_k_e (2.2.2.79).
  4277.  
  4278.  
  4279.  
  4280.  
  4281.                Copyright c 1991 IEEE.  All rights reserved.
  4282.       This is an unapproved IEEE Standards Draft, subject to change.
  4283.  
  4284.  
  4285.  
  4286.  
  4287.  
  4288.  2.2 Definitions                                                        35
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4295.  
  4296.  2.2.2.50  extended regular expression:  A pattern (sequence of characters
  4297.  or symbols) constructed according to the rules defined in 2.8.4.
  4298.  
  4299.  
  4300.  2.2.2.51  extended security controls:  A concept of the underlying
  4301.  system, as follows.  [POSIX.1 {8}]
  4302.  
  4303.  The access control (see _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s) and privilege (see
  4304.  _a_p_p_r_o_p_r_i_a_t_e _p_r_i_v_i_l_e_g_e_s in 2.2.2.6) mechanisms have been defined to allow
  4305.  implementation-defined extended security controls.  These permit an
  4306.  implementation to provide security mechanisms to implement different
  4307.  security policies than described in POSIX.1 {8}.  These mechanisms shall
  4308.  not alter or override the defined semantics of any of the functions in
  4309.  POSIX.1 {8}.
  4310.  
  4311.  2.2.2.52  feature test macro:  A #defined symbol used to determine
  4312.  whether a particular set of features will be included from a header.
  4313.  
  4314.  See POSIX.1 {8} 2.7.1.  [POSIX.1 {8}]
  4315.  
  4316.  
  4317.  2.2.2.53  FIFO special file [FIFO]:  A type of file with the property
  4318.  that data written to such a file is read on a first-in-first-out basis.
  4319.  
  4320.  Other characteristics of _F_I_F_Os are described in POSIX.1 {8} 5.3.1
  4321.  [_o_p_e_n()], 6.4.1 [_r_e_a_d()], 6.4.2 [_w_r_i_t_e()], and 6.5.3 [_l_s_e_e_k()].
  4322.  [POSIX.1 {8}]
  4323.  
  4324.  2.2.2.54  file:  An object that can be written to, or read from, or both.
  4325.  
  4326.  A file has certain attributes, including access permissions and type.
  4327.  File types include regular file, character special file, block special
  4328.  file, FIFO special file, and directory.  Other types of files may be
  4329.  defined by the implementation.  [POSIX.1 {8}]
  4330.  
  4331.  
  4332.  2.2.2.55  file access permissions:  A concept of the underlying system,
  4333.  as follows.  [POSIX.1 {8}]
  4334.  
  4335.  The standard file access control mechanism uses the file permission bits,
  4336.  as described below.  These bits are set at file creation by _o_p_e_n(),
  4337.  _c_r_e_a_t(), _m_k_d_i_r(), and _m_k_f_i_f_o() and are changed by _c_h_m_o_d().  These bits
  4338.  are read by _s_t_a_t() or _f_s_t_a_t().
  4339.  
  4340.  Implementations may provide _a_d_d_i_t_i_o_n_a_l or _a_l_t_e_r_n_a_t_e file access control
  4341.  mechanisms, or both.  An additional access control mechanism shall only
  4342.  further restrict the access permissions defined by the file permission
  4343.  bits.  An alternate access control mechanism shall:
  4344.  
  4345.  
  4346.  
  4347.                Copyright c 1991 IEEE.  All rights reserved.
  4348.       This is an unapproved IEEE Standards Draft, subject to change.
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354.  36                                 2 Terminology and General Requirements
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4361.  
  4362.      (1)  Specify file permission bits for the file owner class, file
  4363.           group class, and file other class of the file, corresponding to
  4364.           the access permissions, to be returned by _s_t_a_t() or _f_s_t_a_t().
  4365.  
  4366.      (2)  Be enabled only by explicit user action, on a per-file basis by
  4367.           the file owner or a user with the appropriate privilege.
  4368.  
  4369.      (3)  Be disabled for a file after the file permission bits are
  4370.           changed for that file with _c_h_m_o_d().  The disabling of the
  4371.           alternate mechanism need not disable any additional mechanisms
  4372.           defined by an implementation.
  4373.  
  4374.  Whenever a process requests file access permission for read, write, or
  4375.  execute/search, if no additional mechanism denies access, access is
  4376.  determined as follows:
  4377.  
  4378.      (1)  If a process has the appropriate privilege:
  4379.  
  4380.            (a)  If read, write, or directory search permission is
  4381.                 requested, access is granted.
  4382.  
  4383.            (b)  If execute permission is requested, access is granted if
  4384.                 execute permission is granted to at least one user by the
  4385.                 file permission bits or by an alternate access control
  4386.                 mechanism; otherwise, access is denied.
  4387.  
  4388.      (2)  Otherwise:
  4389.  
  4390.            (a)  The file permission bits of a file contain read, write,
  4391.                 and execute/search permissions for the file owner class,
  4392.                 file group class, and file other class.
  4393.  
  4394.            (b)  Access is granted if an alternate access control mechanism
  4395.                 is not enabled and the requested access permission bit is
  4396.                 set for the class (file owner class, file group class, or
  4397.                 file other class) to which the process belongs, or if an
  4398.                 alternate access control mechanism is enabled and it
  4399.                 allows the requested access; otherwise, access is denied.
  4400.  
  4401.  
  4402.  2.2.2.56  file descriptor:  A per-process unique, nonnegative integer
  4403.  used to identify an open file for the purpose of file access.
  4404.  [POSIX.1 {8}]
  4405.  
  4406.  2.2.2.57  file group class:  The property of a file indicating access
  4407.  permissions for a process related to the process's group identification.
  4408.  
  4409.  A process is in the file group class of a file if the process is not in
  4410.  the file owner class and if the effective group ID or one of the
  4411.  
  4412.  
  4413.                Copyright c 1991 IEEE.  All rights reserved.
  4414.       This is an unapproved IEEE Standards Draft, subject to change.
  4415.  
  4416.  
  4417.  
  4418.  
  4419.  
  4420.  2.2 Definitions                                                        37
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4427.  
  4428.  supplementary group IDs of the process matches the group ID associated
  4429.  with the file.  Other members of the class may be implementation defined.
  4430.  [POSIX.1 {8}]
  4431.  
  4432.  
  4433.  2.2.2.58  file hierarchy:  A concept of the underlying system, as
  4434.  follows.  [POSIX.1 {8}]
  4435.  
  4436.  Files in the system are organized in a hierarchical structure in which
  4437.  all of the nonterminal nodes are directories and all of the terminal
  4438.  nodes are any other type of file.  Because multiple directory entries may
  4439.  refer to the same file, the hierarchy is properly described as a
  4440.  ``directed graph.''
  4441.  
  4442.  2.2.2.59  file mode:  An object containing the file permission bits and
  4443.  other characteristics of a file, as described in POSIX.1 {8} 5.6.1.
  4444.  [POSIX.1 {8}]
  4445.  
  4446.  
  4447.  2.2.2.60  file mode bits:  A file's file permission bits, set-user-ID-
  4448.  on-execution bit (S_ISUID), and set-group-ID-on-execution bit (S_ISGID)
  4449.  (see POSIX.1 {8} 5.6.1.2).
  4450.  
  4451.  2.2.2.61  filename:  A name consisting of 1 to {NAME_MAX} bytes used to
  4452.  name a file.
  4453.  
  4454.  The characters composing the name may be selected from the set of all
  4455.  character values excluding the slash character and the null character.
  4456.  The filenames dot and dot-dot have special meaning; see _p_a_t_h_n_a_m_e
  4457.  _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.  A filename is sometimes referred to as a
  4458.  pathname component.  [POSIX.1 {8}]
  4459.  
  4460.  
  4461.  2.2.2.62  filename portability:  A concept of the underlying system, as
  4462.  follows.  [POSIX.1 {8}]
  4463.  
  4464.  Filenames should be constructed from the portable filename character set
  4465.  because the use of other characters can be confusing or ambiguous in
  4466.  certain contexts.
  4467.  
  4468.  2.2.2.63  file offset:  The byte position in the file where the next I/O
  4469.  operation begins.
  4470.  
  4471.  Each open file description associated with a regular file, block special
  4472.  file, or directory has a file offset.  A character special file that does
  4473.  not refer to a terminal device may have a file offset.  There is no file
  4474.  offset specified for a pipe or FIFO.  [POSIX.1 {8}]
  4475.  
  4476.  
  4477.  
  4478.  
  4479.                Copyright c 1991 IEEE.  All rights reserved.
  4480.       This is an unapproved IEEE Standards Draft, subject to change.
  4481.  
  4482.  
  4483.  
  4484.  
  4485.  
  4486.  38                                 2 Terminology and General Requirements
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4493.  
  4494.  2.2.2.64  file other class:  The property of a file indicating access
  4495.  permissions for a process related to the process's user and group
  4496.  identification.
  4497.  
  4498.  A process is in the file other class of a file if the process is not in
  4499.  the file owner class or file group class.  [POSIX.1 {8}]
  4500.  
  4501.  
  4502.  2.2.2.65  file owner class:  The property of a file indicating access
  4503.  permissions for a process related to the process's user identification.
  4504.  
  4505.  A process is in the file owner class of a file if the effective user ID
  4506.  of the process matches the user ID of the file.  [POSIX.1 {8}]
  4507.  
  4508.  2.2.2.66  file permission bits:  Information about a file that is used,
  4509.  along with other information, to determine if a process has read, write,
  4510.  or execute/search permission to a file.
  4511.  
  4512.  The bits are divided into three parts:  owner, group, and other.  Each
  4513.  part is used with the corresponding file class of processes.  These bits
  4514.  are contained in the file mode, as described in POSIX.1 {8} 5.6.1.  The
  4515.  detailed usage of the file permission bits in access decisions is
  4516.  described in _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s in 2.2.2.55.  [POSIX.1 {8}]
  4517.  
  4518.  
  4519.  2.2.2.67  file serial number:  A per-file-system unique identifier for a
  4520.  file.
  4521.  
  4522.  File serial numbers are unique throughout a file system.  [POSIX.1 {8}]
  4523.  
  4524.  2.2.2.68  file system:  A collection of files and certain of their
  4525.  attributes.
  4526.  
  4527.  It provides a name space for file serial numbers referring to those
  4528.  files.  [POSIX.1 {8}]
  4529.  
  4530.  
  4531.  2.2.2.69  file times update:  A concept of the underlying system, as
  4532.  follows.  [POSIX.1 {8}]
  4533.  
  4534.  Each file has three distinct associated time values:  _s_t__a_t_i_m_e, _s_t__m_t_i_m_e,
  4535.  and _s_t__c_t_i_m_e.  The _s_t__a_t_i_m_e field is associated with the times that the
  4536.  file data is accessed; _s_t__m_t_i_m_e is associated with the times that the
  4537.  file data is modified; and _s_t__c_t_i_m_e is associated with the times that
  4538.  file status is changed.  These values are returned in the file
  4539.  characteristics structure, as described in POSIX.1 {8} 5.6.1.
  4540.  
  4541.  Any function in this standard that is required to read or write file data
  4542.  or change the file status indicates which of the appropriate time-related
  4543.  fields are to be ``marked for update.''  If an implementation of such a
  4544.  
  4545.                Copyright c 1991 IEEE.  All rights reserved.
  4546.       This is an unapproved IEEE Standards Draft, subject to change.
  4547.  
  4548.  
  4549.  
  4550.  
  4551.  
  4552.  2.2 Definitions                                                        39
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4559.  
  4560.  function marks for update a time-related field not specified by this
  4561.  standard, this shall be documented, except that any changes caused by
  4562.  pathname resolution need not be documented.  For the other functions in
  4563.  this standard (those that are not explicitly required to read or write
  4564.  file data or change file status, but that in some implementations happen
  4565.  to do so), the effect is unspecified.
  4566.  
  4567.  An implementation may update fields that are marked for update
  4568.  immediately, or it may update such fields periodically.  When the fields
  4569.  are updated, they are set to the current time and the update marks are
  4570.  cleared.  All fields that are marked for update shall be updated when the
  4571.  file is no longer open by any process, or when a _s_t_a_t() or _f_s_t_a_t() is
  4572.  performed on the file.  Other times at which updates are done are
  4573.  unspecified.  Updates are not done for files on read-only file systems.
  4574.  
  4575.  
  4576.  2.2.2.70  file type:  See _f_i_l_e in 2.2.2.54.
  4577.  
  4578.  2.2.2.71  filter:  A command whose operation consists of reading data
  4579.  from standard input or a list of input files and writing data to standard
  4580.  output.
  4581.  
  4582.  Typically, its function is to perform some transformation on the data
  4583.  stream.
  4584.  
  4585.  
  4586.  2.2.2.72  foreground process:  A process that is a member of a foreground
  4587.  process group.  [POSIX.1 {8}]
  4588.  
  4589.  2.2.2.73  foreground process group:  A process group whose member
  4590.  processes have certain privileges, denied to processes in background
  4591.  process groups, when accessing their controlling terminal.
  4592.  
  4593.  Each session that has established a connection with a controlling
  4594.  terminal has exactly one process group of the session as the foreground
  4595.  process group of that controlling terminal.  See POSIX.1 {8} 7.1.1.4.
  4596.  [POSIX.1 {8}]
  4597.  
  4598.  
  4599.  2.2.2.74  <form-feed>:  A character that in the output stream shall        1
  4600.  indicate that printing should start on the next page of an output device.
  4601.  
  4602.  The <form-feed> shall be the character designated by '\f' in the C
  4603.  language binding.  If <form-feed> is not the first character of an output
  4604.  line, the result is unspecified.  It is unspecified whether this
  4605.  character is the exact sequence transmitted to an output device by the
  4606.  system to accomplish the movement to the next page.
  4607.  
  4608.  
  4609.  
  4610.  
  4611.                Copyright c 1991 IEEE.  All rights reserved.
  4612.       This is an unapproved IEEE Standards Draft, subject to change.
  4613.  
  4614.  
  4615.  
  4616.  
  4617.  
  4618.  40                                 2 Terminology and General Requirements
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4625.  
  4626.  2.2.2.75  group ID:  A nonnegative integer, which can be contained in an
  4627.  object of type _g_i_d__t, that is used to identify a group of system users.
  4628.  
  4629.  Each system user is a member of at least one group.  When the identity of
  4630.  a group is associated with a process, a group ID value is referred to as
  4631.  a real group ID, an effective group ID, one of the (optional)
  4632.  supplementary group IDs, or an (optional) saved set-group-ID.
  4633.  [POSIX.1 {8}]
  4634.  
  4635.  
  4636.  2.2.2.76  hard link:  The relationship between two directory entries that
  4637.  represent the same file; the result of an execution of the ln utility or
  4638.  the POSIX.1 {8} _l_i_n_k() function.
  4639.  
  4640.  2.2.2.77  home directory:  The current directory associated with a user
  4641.  at the time of login.
  4642.  
  4643.  
  4644.  2.2.2.78  incomplete line:  A sequence of text consisting of one or more
  4645.  non-<newline> characters at the end of the file.
  4646.  
  4647.  2.2.2.79  invoke:  To perform the actions described in 3.9.1.1, except
  4648.  that searching for shell functions and special built-ins is suppressed.
  4649.  
  4650.  See also _e_x_e_c_u_t_e (2.2.2.49).
  4651.  
  4652.  
  4653.  2.2.2.80  job control:  A facility that allows users to selectively stop
  4654.  (suspend) the execution of processes and continue (resume) their
  4655.  execution at a later point.
  4656.  
  4657.  The user typically employs this facility via the interactive interface
  4658.  jointly supplied by the terminal I/O driver and a command interpreter.
  4659.  POSIX.1 {8} conforming implementations may optionally support job control
  4660.  facilities; the presence of this option is indicated to the application
  4661.  at compile time or run time by the definition of the {_POSIX_JOB_CONTROL}
  4662.  symbol; see POSIX.1 {8} 2.9.  [POSIX.1 {8}]
  4663.  
  4664.  2.2.2.81  line:  A sequence of text consisting of zero or more non-
  4665.  <newline> characters plus a terminating <newline> character.
  4666.  
  4667.  
  4668.  2.2.2.82  link:  See _d_i_r_e_c_t_o_r_y _e_n_t_r_y in 2.2.2.36.
  4669.  
  4670.  2.2.2.83  link count:  The number of directory entries that refer to a
  4671.  particular file.  [POSIX.1 {8}]
  4672.  
  4673.  
  4674.  
  4675.  
  4676.  
  4677.                Copyright c 1991 IEEE.  All rights reserved.
  4678.       This is an unapproved IEEE Standards Draft, subject to change.
  4679.  
  4680.  
  4681.  
  4682.  
  4683.  
  4684.  2.2 Definitions                                                        41
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4691.  
  4692.  2.2.2.84  locale:  The definition of the subset of a user's environment
  4693.  that depends on language and cultural conventions; see 2.5.
  4694.  
  4695.  
  4696.  2.2.2.85  login:  The unspecified activity by which a user gains access
  4697.  to the system.
  4698.  
  4699.  Each login shall be associated with exactly one login name.
  4700.  [POSIX.1 {8}]
  4701.  
  4702.  2.2.2.86  login name:  A user name that is associated with a login.
  4703.  [POSIX.1 {8}]
  4704.  
  4705.  
  4706.  2.2.2.87  mode:  A collection of attributes that specifies a file's type
  4707.  and its access permissions.
  4708.  
  4709.  See _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s in 2.2.2.55.  [POSIX.1 {8}]
  4710.  
  4711.  2.2.2.88  multicharacter collating element:  A sequence of two or more
  4712.  characters that collate as an entity.
  4713.  
  4714.  For example, in some coded character sets, an accented character is
  4715.  represented by a (nonspacing) accent, followed by the letter.  Another
  4716.  example is the Spanish elements ``ch'' and ``ll.''
  4717.  
  4718.  
  4719.  2.2.2.89  negative response:  An input string that matches one of the
  4720.  responses acceptable to the LC_MESSAGES category keyword noexpr, matching
  4721.  an extended regular expression in the current locale.
  4722.  
  4723.  See 2.5.
  4724.  
  4725.  2.2.2.90  <newline>:  A character that in the output stream shall          1
  4726.  indicate that printing should start at the beginning of the next line.
  4727.  
  4728.  The <newline> shall be the character designated by '\n' in the C language
  4729.  binding.  It is unspecified whether this character is the exact sequence
  4730.  transmitted to an output device by the system to accomplish the movement
  4731.  to the next line.
  4732.  
  4733.  
  4734.  2.2.2.91  NUL:  A character with all bits set to zero.
  4735.  
  4736.  2.2.2.92  null string:  See _e_m_p_t_y _s_t_r_i_n_g in 2.2.2.45.
  4737.  
  4738.  
  4739.  
  4740.  
  4741.  
  4742.  
  4743.                Copyright c 1991 IEEE.  All rights reserved.
  4744.       This is an unapproved IEEE Standards Draft, subject to change.
  4745.  
  4746.  
  4747.  
  4748.  
  4749.  
  4750.  42                                 2 Terminology and General Requirements
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4757.  
  4758.  2.2.2.93  number-sign:  The character ``#''.
  4759.  
  4760.  This standard permits the substitution of the ``pound sign'' graphic
  4761.  defined in ISO/IEC 646 {1} for this symbol when the character set being
  4762.  used has substituted that graphic for the graphic #.  The graphic symbol
  4763.  # is always used in this standard.
  4764.  
  4765.  
  4766.  2.2.2.94  object file:  A regular file containing the output of a
  4767.  compiler, formatted as input to a linkage editor for linking with other
  4768.  object files into an executable form.
  4769.  
  4770.  The methods of linking are unspecified and may involve the dynamic
  4771.  linking of objects at run-time.  The internal format of an object file is
  4772.  unspecified, but a conforming application shall not assume an object file
  4773.  is a text file.
  4774.  
  4775.  2.2.2.95  open file:  A file that is currently associated with a file
  4776.  descriptor.  [POSIX.1 {8}]
  4777.  
  4778.  
  4779.  2.2.2.96  operand:  An argument to a command that is generally used as an
  4780.  object supplying information to a utility necessary to complete its
  4781.  processing.
  4782.  
  4783.  Operands generally follow the options in a command line.  See 2.10.1.
  4784.  
  4785.  2.2.2.97  option:  An argument to a command that is generally used to
  4786.  specify changes in the _u_t_i_l_i_t_y's default behavior; see 2.10.1.
  4787.  
  4788.  
  4789.  2.2.2.98  option-argument:  A parameter that follows certain options.
  4790.  
  4791.  In some cases an option-argument is included within the same argument
  4792.  string as the option; in most cases it is the next argument.  See 2.10.1.
  4793.  
  4794.  2.2.2.99  parent directory:
  4795.  
  4796.      (1)  When discussing a given directory, the directory that both
  4797.           contains a directory entry for the given directory and is
  4798.           represented by the pathname dot-dot in the given directory.
  4799.  
  4800.      (2)  When discussing other types of files, a directory containing a
  4801.           directory entry for the file under discussion.
  4802.  
  4803.  This concept does not apply to dot and dot-dot.  [POSIX.1 {8}]
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.                Copyright c 1991 IEEE.  All rights reserved.
  4810.       This is an unapproved IEEE Standards Draft, subject to change.
  4811.  
  4812.  
  4813.  
  4814.  
  4815.  
  4816.  2.2 Definitions                                                        43
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4823.  
  4824.  2.2.2.100  parent process:  See _p_r_o_c_e_s_s in 2.2.2.114.  [POSIX.1 {8}]
  4825.  
  4826.  
  4827.  2.2.2.101  parent process ID:  An attribute of a new process after it is
  4828.  created by a currently active process.
  4829.  
  4830.  The parent process ID of a process is the process ID of its creator, for
  4831.  the lifetime of the creator.  After the creator's lifetime has ended, the
  4832.  parent process ID is the process ID of an implementation-defined system
  4833.  process.  [POSIX.1 {8}]
  4834.  
  4835.  2.2.2.102  pathname:  A string that is used to identify a file.
  4836.  
  4837.  A pathname consists of, at most, {PATH_MAX} bytes, including the
  4838.  terminating null character.  It has an optional beginning slash, followed
  4839.  by zero or more filenames separated by slashes.  If the pathname refers
  4840.  to a directory, it may also have one or more trailing slashes.  Multiple
  4841.  successive slashes are considered to be the same as one slash.  A
  4842.  pathname that begins with two successive slashes may be interpreted in an
  4843.  implementation-defined manner, although more than two leading slashes
  4844.  shall be treated as a single slash.  The interpretation of the pathname
  4845.  is described in _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.  [POSIX.1 {8}]
  4846.  
  4847.  
  4848.  2.2.2.103  pathname component:  See _f_i_l_e_n_a_m_e in 2.2.2.61.  [POSIX.1 {8}]
  4849.  
  4850.  2.2.2.104  pathname resolution:  A concept of the underlying system, as
  4851.  follows.  [POSIX.1 {8}]
  4852.  
  4853.  Pathname resolution is performed for a process to resolve a pathname to a
  4854.  particular file in a file hierarchy.  There may be multiple pathnames
  4855.  that resolve to the same file.
  4856.  
  4857.  Each filename in the pathname is located in the directory specified by
  4858.  its predecessor (for example, in the pathname fragment ``a/b'', file
  4859.  ``b'' is located in directory ``a'').  Pathname resolution fails if this
  4860.  cannot be accomplished.  If the pathname begins with a slash, the
  4861.  predecessor of the first filename in the pathname is taken to be the root
  4862.  directory of the process (such pathnames are referred to as absolute
  4863.  pathnames).  If the pathname does not begin with a slash, the predecessor
  4864.  of the first filename of the pathname is taken to be the current working
  4865.  directory of the process (such pathnames are referred to as ``relative
  4866.  pathnames'').
  4867.  
  4868.  The interpretation of a pathname component is dependent on the values of
  4869.  {NAME_MAX} and {_POSIX_NO_TRUNC} associated with the path prefix of that
  4870.  component.  If any pathname component is longer than {NAME_MAX}, and
  4871.  {_POSIX_NO_TRUNC} is in effect for the path prefix of that component [see
  4872.  _p_a_t_h_c_o_n_f() in POSIX.1 {8} 5.7.1], the implementation shall consider this
  4873.  
  4874.  
  4875.                Copyright c 1991 IEEE.  All rights reserved.
  4876.       This is an unapproved IEEE Standards Draft, subject to change.
  4877.  
  4878.  
  4879.  
  4880.  
  4881.  
  4882.  44                                 2 Terminology and General Requirements
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  4889.  
  4890.  an error condition.  Otherwise, the implementation shall use the first
  4891.  {NAME_MAX} bytes of the pathname component.
  4892.  
  4893.  The special filename dot refers to the directory specified by its
  4894.  predecessor.  The special filename dot-dot refers to the parent directory
  4895.  of its predecessor directory.  As a special case, in the root directory,
  4896.  dot-dot may refer to the root directory itself.
  4897.  
  4898.  A pathname consisting of a single slash resolves to the root directory of
  4899.  the process.  A null pathname is invalid.
  4900.  
  4901.  
  4902.  2.2.2.105  path prefix:  A pathname, with an optional ending slash, that
  4903.  refers to a directory.  [POSIX.1 {8}]
  4904.  
  4905.  2.2.2.106  pattern:  A sequence of characters used either with regular
  4906.  expression notation (see 2.8) or for pathname expansion (see 3.6.6), as a
  4907.  means of selecting various character strings or pathnames, respectively.
  4908.  
  4909.  The syntaxes of the two patterns are similar, but not identical; this
  4910.  standard always indicates the type of pattern being referred to in the
  4911.  immediate context of the use of the term.
  4912.  
  4913.  
  4914.  2.2.2.107  period:  The character ``.''.
  4915.  
  4916.  The term _p_e_r_i_o_d is contrasted against _d_o_t (2.2.2.38), which is used to
  4917.  describe a specific directory entry.
  4918.  
  4919.  2.2.2.108  permissions:  See _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s in 2.2.2.55.
  4920.  
  4921.  
  4922.  2.2.2.109  pipe:  An object accessed by one of the pair of file
  4923.  descriptors created by the POSIX.1 {8} _p_i_p_e() function.
  4924.  
  4925.  Once created, the file descriptors can be used to manipulate it, and it
  4926.  behaves identically to a FIFO special file when accessed in this way.  It
  4927.  has no name in the file hierarchy.  [POSIX.1 {8}]
  4928.  
  4929.  2.2.2.110  portable character set:  The set of characters described in
  4930.  2.4 that is supported on all conforming systems.
  4931.  
  4932.  This term is contrasted against the smaller _p_o_r_t_a_b_l_e _f_i_l_e_n_a_m_e _c_h_a_r_a_c_t_e_r
  4933.  _s_e_t; see 2.2.2.111.
  4934.  
  4935.  
  4936.  2.2.2.111  portable filename character set:  The set of characters from
  4937.  which portable filenames are constructed.
  4938.  
  4939.  
  4940.  
  4941.                Copyright c 1991 IEEE.  All rights reserved.
  4942.       This is an unapproved IEEE Standards Draft, subject to change.
  4943.  
  4944.  
  4945.  
  4946.  
  4947.  
  4948.  2.2 Definitions                                                        45
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  4955.  
  4956.  For a filename to be portable across conforming implementations of this
  4957.  standard, it shall consist only of the following characters:
  4958.  
  4959.        A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  4960.        a b c d e f g h i j k l m n o p q r s t u v w x y z
  4961.        0 1 2 3 4 5 6 7 8 9 . _ -
  4962.  
  4963.  The last three characters are the period, underscore, and hyphen
  4964.  characters, respectively.  The hyphen shall not be used as the first
  4965.  character of a portable filename.  Upper- and lowercase letters shall
  4966.  retain their unique identities between conforming implementations.  In
  4967.  the case of a portable pathname, the slash character may also be used.
  4968.  [POSIX.1 {8}]
  4969.  
  4970.  
  4971.  2.2.2.112  printable character:  One of the characters included in the
  4972.  print character classification of the LC_CTYPE category in the current
  4973.  locale; see 2.5.2.1.
  4974.  
  4975.  2.2.2.113  privilege:  See _a_p_p_r_o_p_r_i_a_t_e _p_r_i_v_i_l_e_g_e_s in 2.2.2.6.
  4976.  [POSIX.1 {8}]
  4977.  
  4978.  
  4979.  2.2.2.114  process:  An address space and single thread of control that
  4980.  executes within that address space, and its required system resources.
  4981.  
  4982.  A process is created by another process issuing the POSIX.1 {8} _f_o_r_k()
  4983.  function.  The process that issues _f_o_r_k() is known as the parent process,
  4984.  and the new process created by the _f_o_r_k() is known as the child process.
  4985.  [POSIX.1 {8}]
  4986.  
  4987.  The attributes of processes required by POSIX.2 form a subset of those in
  4988.  POSIX.1 {8}; see 2.9.1.
  4989.  
  4990.  2.2.2.115  process group:  A collection of processes that permits the
  4991.  signaling of related processes.
  4992.  
  4993.  Each process in the system is a member of a process group that is
  4994.  identified by a process group ID.  A newly created process joins the
  4995.  process group of its creator.  [POSIX.1 {8}]
  4996.  
  4997.  
  4998.  2.2.2.116  process group ID:  The unique identifier representing a
  4999.  process group during its lifetime.
  5000.  
  5001.  A process group ID is a positive integer that can be contained in a
  5002.  _p_i_d__t.  It shall not be reused by the system until the process group
  5003.  lifetime ends.  [POSIX.1 {8}]
  5004.  
  5005.  
  5006.  
  5007.                Copyright c 1991 IEEE.  All rights reserved.
  5008.       This is an unapproved IEEE Standards Draft, subject to change.
  5009.  
  5010.  
  5011.  
  5012.  
  5013.  
  5014.  46                                 2 Terminology and General Requirements
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5021.  
  5022.  2.2.2.117  process group leader:  A process whose process ID is the same
  5023.  as its process group ID.  [POSIX.1 {8}]
  5024.  
  5025.  
  5026.  2.2.2.118  process ID:  The unique identifier representing a process.
  5027.  
  5028.  A process ID is a positive integer that can be contained in a _p_i_d__t.  A
  5029.  process ID shall not be reused by the system until the process lifetime
  5030.  ends.  In addition, if there exists a process group whose process group
  5031.  ID is equal to that process ID, the process ID shall not be reused by the
  5032.  system until the process group lifetime ends.  A process that is not a
  5033.  system process shall not have a process ID of 1.  [POSIX.1 {8}]
  5034.  
  5035.  2.2.2.119  program:  A prepared sequence of instructions to the system to
  5036.  accomplish a defined task.
  5037.  
  5038.  The term _p_r_o_g_r_a_m in POSIX.2 encompasses applications written in the Shell
  5039.  Command Language, complex utility input languages (for example, awk, lex,
  5040.  sed, etc.), and high-level languages.
  5041.  
  5042.  
  5043.  2.2.2.120  read-only file system:  A file system that has
  5044.  implementation-defined characteristics restricting modifications.
  5045.  [POSIX.1 {8}]
  5046.  
  5047.  2.2.2.121  real group ID:  The attribute of a process that, at the time
  5048.  of process creation, identifies the group of the user who created the
  5049.  process.
  5050.  
  5051.  See _g_r_o_u_p _I_D in 2.2.2.75.  This value is subject to change during the
  5052.  process lifetime, as described in POSIX.1 {8} 4.2.2 [_s_e_t_g_i_d()].
  5053.  [POSIX.1 {8}]
  5054.  
  5055.  
  5056.  2.2.2.122  real user ID:  The attribute of a process that, at the time of
  5057.  process creation, identifies the user who created the process.
  5058.  
  5059.  See _u_s_e_r _I_D in 2.2.2.154.  This value is subject to change during the
  5060.  process lifetime, as described in POSIX.1 {8} 4.2.2 [_s_e_t_u_i_d()].
  5061.  [POSIX.1 {8}]
  5062.  
  5063.  2.2.2.123  regular expression:  A pattern (sequence of characters or       1
  5064.  symbols) constructed according to the rules defined in 2.8.                1
  5065.  
  5066.  
  5067.  2.2.2.124  regular file:  A file that is a randomly accessible sequence
  5068.  of bytes, with no further structure imposed by the system.  [POSIX.1 {8}]
  5069.  
  5070.  
  5071.  
  5072.  
  5073.                Copyright c 1991 IEEE.  All rights reserved.
  5074.       This is an unapproved IEEE Standards Draft, subject to change.
  5075.  
  5076.  
  5077.  
  5078.  
  5079.  
  5080.  2.2 Definitions                                                        47
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5087.  
  5088.  2.2.2.125  relative pathname:  See _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in 2.2.2.104.
  5089.  [POSIX.1 {8}]
  5090.  
  5091.  
  5092.  2.2.2.126  root directory:  A directory, associated with a process, that
  5093.  is used in pathname resolution for pathnames that begin with a slash.
  5094.  [POSIX.1 {8}]
  5095.  
  5096.  2.2.2.127  saved set-group-ID:  An attribute of a process that allows
  5097.  some flexibility in the assignment of the effective group ID attribute,
  5098.  when the saved set-user-ID option is implemented, as described in
  5099.  POSIX.1 {8} 3.1.2 (_e_x_e_c) and 4.2.2 [_s_e_t_g_i_d()].  [POSIX.1 {8}]
  5100.  
  5101.  
  5102.  2.2.2.128  saved set-user-ID:  An attribute of a process that allows some
  5103.  flexibility in the assignment of the effective user ID attribute, when
  5104.  the saved set-user-ID option is implemented, as described in POSIX.1 {8}
  5105.  3.1.2 and 4.2.2 [_s_e_t_u_i_d()].  [POSIX.1 {8}]
  5106.  
  5107.  2.2.2.129  seconds since the Epoch:  A value to be interpreted as the
  5108.  number of seconds between a specified time and the Epoch.
  5109.  
  5110.  A Coordinated Universal Time name [specified in terms of seconds
  5111.  (_t_m__s_e_c), minutes (_t_m__m_i_n), hours (_t_m__h_o_u_r), days since January 1 of the
  5112.  year (_t_m__y_d_a_y), and calendar year minus 1900 (_t_m__y_e_a_r)] is related to a
  5113.  time represented as seconds since the Epoch, according to the expression
  5114.  below.
  5115.  
  5116.  If the year < 1970 or the value is negative, the relationship is
  5117.  undefined.  If the year _> 1970 and the value is nonnegative, the value is
  5118.  related to a Coordinated Universal Time name according to the expression:
  5119.  
  5120.        _t_m__s_e_c + _t_m__m_i_n*60 + _t_m__h_o_u_r*3600 + _t_m__y_d_a_y*86400 +
  5121.            (_t_m__y_e_a_r-70)*31536000 + ((_t_m__y_e_a_r-69)/4)*86400
  5122.  
  5123.  [POSIX.1 {8}]
  5124.  
  5125.  
  5126.  2.2.2.130  session:  A collection of process groups established for job
  5127.  control purposes.
  5128.  
  5129.  Each process group is a member of a session.  A process is considered to
  5130.  be a member of the session of which its process group is a member.  A
  5131.  newly created process joins the session of its creator.  A process can
  5132.  alter its session membership (see POSIX.1 {8} 4.3.2 [_s_e_t_s_i_d()].
  5133.  Implementations that support the POSIX.1 {8} _s_e_t_p_g_i_d() function (see
  5134.  POSIX.1 {8} 4.3.3) can have multiple process groups in the same session.
  5135.  [POSIX.1 {8}]
  5136.  
  5137.  
  5138.  
  5139.                Copyright c 1991 IEEE.  All rights reserved.
  5140.       This is an unapproved IEEE Standards Draft, subject to change.
  5141.  
  5142.  
  5143.  
  5144.  
  5145.  
  5146.  48                                 2 Terminology and General Requirements
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5153.  
  5154.  2.2.2.131  session leader:  A process that has created a session; see
  5155.  POSIX.1 {8} 4.3.2 [_s_e_t_s_i_d()].  [POSIX.1 {8}]
  5156.  
  5157.  
  5158.  2.2.2.132  session lifetime:  The period between when a session is
  5159.  created and the end of the lifetime of all the process groups that remain
  5160.  as members of the session.  [POSIX.1 {8}]
  5161.  
  5162.  2.2.2.133  shell:  A program that interprets sequences of text input as
  5163.  commands.
  5164.  
  5165.  It may operate on an input stream or it may interactively prompt and read
  5166.  commands from a terminal.
  5167.  
  5168.  
  5169.  2.2.2.134  Shell, The:  The Shell Command Language Interpreter (see
  5170.  4.56), a specific instance of a shell.
  5171.  
  5172.  2.2.2.135  shell script:  A file containing shell commands.
  5173.  
  5174.  If the file is made executable, it can be executed by specifying its name
  5175.  as a simple command (see the description of _s_i_m_p_l_e _c_o_m_m_a_n_d in 3.9.1).
  5176.  Execution of a shell script causes a shell to execute the commands within
  5177.  the script.  Alternately, a shell can be requested to execute the
  5178.  commands in a shell script by specifying the name of the shell script as
  5179.  the operand to the sh utility.
  5180.  
  5181.  
  5182.  2.2.2.136  signal:  A mechanism by which a process may be notified of, or
  5183.  affected by, an event occurring in the system.
  5184.  
  5185.  Examples of such events include hardware exceptions and specific actions
  5186.  by processes.  The term _s_i_g_n_a_l is also used to refer to the event itself.
  5187.  [POSIX.1 {8}]
  5188.  
  5189.  2.2.2.137  single-quote:  The character ``''', also known as _a_p_o_s_t_r_o_p_h_e.
  5190.  
  5191.  
  5192.  2.2.2.138  slash:  The character ``/'', also known as _s_o_l_i_d_u_s.
  5193.  
  5194.  2.2.2.139  source code:  When dealing with the Shell Command Language,
  5195.  source code is input to the command language interpreter.
  5196.  
  5197.  The term _s_h_e_l_l _s_c_r_i_p_t is synonymous with this meaning.
  5198.  
  5199.  When dealing with the C Language Bindings Option, source code is input to
  5200.  a C compiler conforming to the C Standard {7}.
  5201.  
  5202.  
  5203.  
  5204.  
  5205.                Copyright c 1991 IEEE.  All rights reserved.
  5206.       This is an unapproved IEEE Standards Draft, subject to change.
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212.  2.2 Definitions                                                        49
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5219.  
  5220.  When dealing with another ISO/IEC conforming language, source code is
  5221.  input to a compiler conforming to that ISO/IEC standard.
  5222.  
  5223.  Source code also refers to the input statements prepared for the
  5224.  following standard utilities:  awk, bc, ed, lex, localedef, make, sed,
  5225.  and yacc.
  5226.  
  5227.  Source code can also refer to a collection of sources meeting any or all
  5228.  of these meanings.
  5229.  
  5230.  
  5231.  _2._2._2._1_4_0  <space>:  The character defined in 2.4 as <space>.
  5232.  
  5233.  The <space> character is a member of the space character class of the
  5234.  current locale, but represents the single character, and not all of the
  5235.  possible members of the class.  (See 2.2.2.158.)
  5236.  
  5237.  2.2.2.141  standard error:  An output stream usually intended to be used
  5238.  for diagnostic messages.
  5239.  
  5240.  
  5241.  2.2.2.142  standard input:  An input stream usually intended to be used
  5242.  for primary data input.
  5243.  
  5244.  2.2.2.143  standard output:  An output stream usually intended to be used
  5245.  for primary data output.
  5246.  
  5247.  
  5248.  2.2.2.144  standard utilities:  The utilities defined by this standard,
  5249.  in the Sections 4, 5, and 6, and Annex A, and Annex C, and in similar
  5250.  sections of utility definitions introduced in future revisions of, and
  5251.  supplements to, this standard.
  5252.  
  5253.  2.2.2.145  stream:  An ordered sequence of characters, as described by
  5254.  the C Standard {7}.
  5255.  
  5256.  
  5257.  2.2.2.146  supplementary group ID:  An attribute of a process used in
  5258.  determining file access permissions.
  5259.  
  5260.  A process has up to {NGROUPS_MAX} supplementary group IDs in addition to
  5261.  the effective group ID.  The supplementary group IDs of a process are set
  5262.  to the supplementary group IDs of the parent process when the process is
  5263.  created.  Whether a process's effective group ID is included in or
  5264.  omitted from its list of supplementary group IDs is unspecified.
  5265.  [POSIX.1 {8}]
  5266.  
  5267.  
  5268.  
  5269.  
  5270.  
  5271.                Copyright c 1991 IEEE.  All rights reserved.
  5272.       This is an unapproved IEEE Standards Draft, subject to change.
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.  50                                 2 Terminology and General Requirements
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5285.  
  5286.  2.2.2.147  system:  An implementation of this standard.
  5287.  
  5288.  
  5289.  2.2.2.148  <tab>:  The horizontal tab character.
  5290.  
  5291.  2.2.2.149  terminal [terminal device]:  A character special file that
  5292.  obeys the specifications of the POSIX.1 {8} General Terminal Interface.
  5293.  [POSIX.1 {8}]
  5294.  
  5295.  
  5296.  2.2.2.150  text column:  A roughly rectangular block of characters
  5297.  capable of being laid out side-by-side next to other text columns on an
  5298.  output page or terminal screen.
  5299.  
  5300.  The widths of text columns are measured in column positions.
  5301.  
  5302.  2.2.2.151  text file:  A file that contains characters organized into one
  5303.  or more lines.
  5304.  
  5305.  The lines shall not contain NUL characters and none shall exceed
  5306.  {LINE_MAX} bytes in length, including the <newline>.  Although
  5307.  POSIX.1 {8} does not distinguish between text files and binary files (see
  5308.  the C Standard {7}), many utilities only produce predictable or
  5309.  meaningful output when operating on text files.  The standard utilities
  5310.  that have such restrictions always specify _t_e_x_t _f_i_l_e_s in their Standard
  5311.  Input or Input Files subclauses.
  5312.  
  5313.  
  5314.  2.2.2.152  tilde:  The character ``~''.
  5315.  
  5316.  2.2.2.153  user database:  See Section 9 in POSIX.1 {8}.
  5317.  
  5318.  
  5319.  2.2.2.154  user ID:  A nonnegative integer, which can be contained in an
  5320.  object of type _u_i_d__t, that is used to identify a system user.
  5321.  
  5322.  When the identity of a user is associated with a process, a user ID value
  5323.  is referred to as a real user ID, an effective user ID, or an (optional)
  5324.  saved set-user-ID.  [POSIX.1 {8}]
  5325.  
  5326.  2.2.2.155  user name:  A string that is used to identify a user, as
  5327.  described in POSIX.1 {8} 9.1.  [POSIX.1 {8}]
  5328.  
  5329.  
  5330.  2.2.2.156  utility:  A program that can be called by name from a shell to
  5331.  perform a specific task, or related set of tasks.
  5332.  
  5333.  This program shall either be an executable file, such as might be
  5334.  produced by a compiler/linker system from computer source code, or a file
  5335.  of shell source code, directly interpreted by the shell.  The program may
  5336.  
  5337.                Copyright c 1991 IEEE.  All rights reserved.
  5338.       This is an unapproved IEEE Standards Draft, subject to change.
  5339.  
  5340.  
  5341.  
  5342.  
  5343.  
  5344.  2.2 Definitions                                                        51
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5351.  
  5352.  have been produced by the user, provided by the implementor of this
  5353.  standard, or acquired from an independent distributor.  The term _u_t_i_l_i_t_y
  5354.  does not apply to the special built-in utilities provided as part of the
  5355.  shell command language; see 3.14.  The system may implement certain
  5356.  utilities as shell functions (see 3.9.5) or built-ins (see 2.3), but only
  5357.  an application that is aware of the command search order described in
  5358.  3.9.1.1 or of performance characteristics can discern differences between
  5359.  the behavior of such a function or built-in and that of a true executable
  5360.  file.
  5361.  
  5362.  
  5363.  _2._2._2._1_5_7  <vertical-tab>:  The vertical tab character.
  5364.  
  5365.  2.2.2.158  white space:  A sequence of one or more characters that belong
  5366.  to the space character class as defined via the LC_CTYPE category in the
  5367.  current locale.
  5368.  
  5369.  In the POSIX Locale, white space consists of one or more <blank>s
  5370.  (<space>s and <tab>s), <newline>s, <carriage-return>s, <form-feed>s, and
  5371.  <vertical-tab>s.
  5372.  
  5373.  
  5374.  2.2.2.159  working directory [current working directory]:  A directory,
  5375.  associated with a process, that is used in pathname resolution for
  5376.  pathnames that do not begin with a slash.
  5377.  
  5378.  2.2.2.160  write:  To output characters to a file, such as standard
  5379.  output or standard error.
  5380.  
  5381.  Unless otherwise stated, standard output is the default output
  5382.  destination for all uses of the term _w_r_i_t_e.
  5383.  
  5384.  BEGIN_RATIONALE
  5385.  
  5386.  
  5387.  2.2.2.161  General Terms Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  5388.             _P_1_0_0_3._2)
  5389.  
  5390.  Many of the terms originated in POSIX.1 {8} and are duplicated in this
  5391.  standard to meet editorial requirements.  In some cases, there is
  5392.  supplementary text that presents additional information concerning
  5393.  POSIX.2 aspects of the concept.
  5394.  
  5395.  This standard uses the term _c_h_a_r_a_c_t_e_r to mean a sequence of one or more
  5396.  bytes representing a single graphic symbol, as defined in POSIX.1 {8}.     1
  5397.  The deviation in the exact text of the C Standard {7} definition for _b_y_t_e  1
  5398.  meets the intent of the C Standard {7} Rationale and the developers of     1
  5399.  POSIX.1 {8}, but clears up the ambiguity raised by the term _b_a_s_i_c          1
  5400.  _e_x_e_c_u_t_i_o_n _c_h_a_r_a_c_t_e_r _s_e_t, which is not defined in POSIX.1 {8}.  It is       1
  5401.  expected that a future version of POSIX.1 {8} will align with the text     1
  5402.  
  5403.                Copyright c 1991 IEEE.  All rights reserved.
  5404.       This is an unapproved IEEE Standards Draft, subject to change.
  5405.  
  5406.  
  5407.  
  5408.  
  5409.  
  5410.  52                                 2 Terminology and General Requirements
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5417.  
  5418.  used here.  The octet-minimum requirement is merely a reflection of the    1
  5419.  {CHAR_BIT} value in POSIX.1 {8} and the C Standard {7}.                    1
  5420.  
  5421.  The POSIX.1 {8} term _f_i_l_e _m_o_d_e is a superset of the POSIX.2 _f_i_l_e _m_o_d_e
  5422.  _b_i_t_s.  POSIX.1 {8} defines the file mode as the entire _m_o_d_e__t object
  5423.  (which includes the file type in historically the upper four bits, the
  5424.  sticky bit on most implementations, and potentially other nonstandardized
  5425.  attributes), while POSIX.2 file mode bits include only the eleven defined
  5426.  bits.
  5427.  
  5428.  The terms _c_o_m_m_a_n_d and _u_t_i_l_i_t_y are related but have distinct meanings.
  5429.  Command is defined as ``a directive to a shell to perform a specific
  5430.  task.''  The directive can be in the form of a single utility name (for
  5431.  example, ls), or the directive can take the form of a compound command
  5432.  (for example, ls | grep name | pr).
  5433.  
  5434.  A utility is a program that is callable by name from a shell.  Issuing
  5435.  only the utility's name to a shell is the equivalent of a one-word
  5436.  command.  A utility may be invoked as a separate program that executes in
  5437.  a different process than the command language interpreter, or may be
  5438.  implemented as a part of the command language interpreter.  For example,
  5439.  the echo command (the directive to perform a specific task) may be
  5440.  implemented such that the echo utility (the logic that performs the task
  5441.  of echoing) is in a separate program; and therefore, is executed in a
  5442.  process that is different than the command language interpreter.
  5443.  Conversely, the logic that performs the echo utility could be built into
  5444.  the command language interpreter; and therefore, execute in the same
  5445.  process as the command language interpreter.
  5446.  
  5447.  The terms _t_o_o_l and _a_p_p_l_i_c_a_t_i_o_n can be thought of as being synonymous with
  5448.  _u_t_i_l_i_t_y from the perspective of the operating system kernel.  Tools,
  5449.  applications, and utilities have historically run, typically, in
  5450.  processes above the kernel level.  Tools and utilities have been
  5451.  historically a part of the operating system nonkernel code, and performed
  5452.  system related functions such as listing directory contents, checking
  5453.  file systems, repairing file systems, or extracting system status
  5454.  information.  Applications have not generally been a part of the
  5455.  operating system, and perform nonsystem related functions such as word
  5456.  processing, architectural design, mechanical design, workstation
  5457.  publishing, or financial analysis.  Utilities have most frequently been
  5458.  provided by the operating system vendor, applications by third party
  5459.  software vendors or by the users themselves.  Nevertheless, the standard
  5460.  does not differentiate between tools, utilities, and applications when it
  5461.  comes to receiving services from the system, a shell, or the standard
  5462.  utilities.  (For example, the xargs utility invokes another utility; it
  5463.  would be of fairly limited usefulness if the users couldn't run their own
  5464.  applications in place of the standard utilities.)  Utilities are not
  5465.  applications in the sense that they are not themselves subjects to the
  5466.  restrictions of this standard or any other standard--there is no
  5467.  
  5468.  
  5469.                Copyright c 1991 IEEE.  All rights reserved.
  5470.       This is an unapproved IEEE Standards Draft, subject to change.
  5471.  
  5472.  
  5473.  
  5474.  
  5475.  
  5476.  2.2 Definitions                                                        53
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5483.  
  5484.  requirement for grep, stty, or any of the utilities defined here to be
  5485.  any of the classes of Conforming POSIX.2 Applications.
  5486.  
  5487.  The term _t_e_x_t _f_i_l_e does not prevent the inclusion of control or other
  5488.  nonprintable characters (other than NUL).  Therefore, standard utilities
  5489.  that list text files as inputs or outputs are either able to process the
  5490.  special characters gracefully or they explicitly describe their
  5491.  limitations within their individual subclauses.  The definition of _t_e_x_t
  5492.  _f_i_l_e has caused a good deal of controversy.  The only difference between
  5493.  text and binary here is that text files have lines of (less than
  5494.  {LINE_MAX}) bytes, with no NUL characters, each terminated by a <newline>
  5495.  character.  The definition allows a file with a single <newline>, but not
  5496.  a totally empty file, to be called a text file.  If a file ends with an
  5497.  incomplete line it is not strictly a text file by this definition.  A
  5498.  related point is that the <newline> character referred to in this
  5499.  standard is not some generic line separator, but a single character;
  5500.  files created on systems where they use multiple characters for ends of
  5501.  lines are not portable to all POSIX systems without some translation
  5502.  process unspecified by this standard.
  5503.  
  5504.  The term _h_a_r_d _l_i_n_k is historically-derived.  In systems without
  5505.  extensions to ln, it is a synonym for _l_i_n_k.  The concept of a _s_y_m_b_o_l_i_c
  5506.  _l_i_n_k originated with BSD systems and the term _h_a_r_d is used to
  5507.  differentiate between the two types of links.
  5508.  
  5509.  There are some terms used that are undefined in POSIX.2, POSIX.1 {8}, or
  5510.  the C Standard {7}.  The working group believes that these terms have a
  5511.  ``common usage,'' and that a definition in POSIX.2 would not be
  5512.  appropriate.  Terms in this category include, but are not limited to, the
  5513.  following:  _a_p_p_l_i_c_a_t_i_o_n, _c_h_a_r_a_c_t_e_r _s_e_t, _l_o_g_i_n _s_e_s_s_i_o_n, _u_s_e_r.  Good
  5514.  sources for general terms of this type are the _I_S_O/_A_F_N_O_R _D_i_c_t_i_o_n_a_r_y _o_f
  5515.  _C_o_m_p_u_t_e_r _S_c_i_e_n_c_e {B12} and _I_E_E_E _D_i_c_t_i_o_n_a_r_y {B18}.
  5516.  
  5517.  The term _f_i_l_e _n_a_m_e was defined in previous drafts to be a synonym for
  5518.  _p_a_t_h_n_a_m_e.  It was removed in the face of objections that it was too close
  5519.  to _f_i_l_e_n_a_m_e, which means something different (a pathname component).  The
  5520.  general solution to this has been to use the term _f_i_l_e in parameter
  5521.  names, rather than _f_i_l_e__n_a_m_e, and to make more liberal use of the correct
  5522.  term, _p_a_t_h_n_a_m_e; an alternate solution has been to replace _f_i_l_e _n_a_m_e with
  5523.  _t_h_e _n_a_m_e _o_f _t_h_e _f_i_l_e.
  5524.  
  5525.  Many character names are included in this subclause.  Because of
  5526.  historical usage, some of these names are a bit different than the ones
  5527.  used in international standards for character sets, such as ISO/IEC 646
  5528.  {1}.  It was felt that many more UNIX system people than character set
  5529.  lawyers would be reading and reviewing the standard, so the former group
  5530.  was the one accommodated.  On the other hand, the precise definitions of
  5531.  <space>, <blank>, and _w_h_i_t_e _s_p_a_c_e have replaced common usage (where they
  5532.  have been used virtually interchangeably), as the standard attempts to
  5533.  
  5534.  
  5535.                Copyright c 1991 IEEE.  All rights reserved.
  5536.       This is an unapproved IEEE Standards Draft, subject to change.
  5537.  
  5538.  
  5539.  
  5540.  
  5541.  
  5542.  54                                 2 Terminology and General Requirements
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5549.  
  5550.  balance readability against precision.
  5551.  
  5552.  In earlier drafts, the names for the character pairs ( ), [ ], and { }
  5553.  were referred to as ``opening'' and ``closing'' parentheses, brackets,
  5554.  and braces.  These were changed to the current ``left'' and right.''
  5555.  When the characters are used to express natural language, the terms
  5556.  ``open'' and ``close'' imply text direction more strongly than ``left''
  5557.  and ``right.''  By POSIX.2 definition, the character <open-parenthesis>
  5558.  will always be mapped to the glyph '(' regardless of the locale.  But
  5559.  when reading right-to-left, the opening punctuation of a parenthesized
  5560.  text segment would be ')'.  The <left-parenthesis> and <right-
  5561.  parenthesis> forms are the correct ones because the punctuation appears
  5562.  on the left and right, respectively, of the parenthesized text regardless
  5563.  of the direction one might be reading the text.
  5564.  
  5565.  The <backspace> character and the ERASE special character defined in
  5566.  POSIX.1 {8} should not be confused.  The use of the <backspace> character
  5567.  and the ERASE special character defined in the POSIX.1 {8} _t_e_r_m_i_o_s clause
  5568.  on special characters (7.1.1.9) are distinct even though the ERASE
  5569.  special character may be set to <backspace>.
  5570.  
  5571.  In most one-byte character sets, such as ASCII, the concepts of column
  5572.  positions is identical to character positions and to bytes.  Therefore,
  5573.  it has been historically acceptable for some implementations to describe
  5574.  line folding or tab stops or table column alignment in terms of bytes or
  5575.  character positions.  Other character sets pose complications, as they
  5576.  can have internal representations longer than one octet and they can have
  5577.  displayable characters that have different widths on the terminal screen
  5578.  or printer.
  5579.  
  5580.  In this standard the term _c_o_l_u_m_n _p_o_s_i_t_i_o_n_s has been defined to mean
  5581.  character--not byte--positions in input files (such as ``column position
  5582.  7 of the FORTRAN input'').  Output files describe the column position in
  5583.  terms of the display width of the narrowest printable character in the
  5584.  character set, adjusted to fit the characteristics of the output device.
  5585.  It is very possible that _n column positions will not be able to hold _n
  5586.  characters in some character sets, unless all of those characters are of
  5587.  the narrowest width.  It is assumed that the implementation is aware of
  5588.  the width of the various characters, deriving this information from the
  5589.  value of LC_CTYPE, and thus can determine how many column positions to
  5590.  allot for each character in those utilities where it is important.  This
  5591.  information is not available to the portable application writer because
  5592.  POSIX.2 provides no interface specification to retrieve such information.
  5593.  
  5594.  The term _c_o_l_u_m_n _p_o_s_i_t_i_o_n was used instead of the more natural _c_o_l_u_m_n as
  5595.  the latter is frequently used in the standard in the different contexts
  5596.  of columns of figures, columns of table values, etc.  Wherever confusion
  5597.  might result, these latter types of columns are referred to as _t_e_x_t
  5598.  _c_o_l_u_m_n_s.
  5599.  
  5600.  
  5601.                Copyright c 1991 IEEE.  All rights reserved.
  5602.       This is an unapproved IEEE Standards Draft, subject to change.
  5603.  
  5604.  
  5605.  
  5606.  
  5607.  
  5608.  2.2 Definitions                                                        55
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5615.  
  5616.  The definition of _b_i_n_a_r_y _f_i_l_e was removed, as the term is not used in the
  5617.  standard.
  5618.  
  5619.  The ISO/IEC 646 {1} character set standard permits substitution of
  5620.  national currency symbols for the character $ in the ``reference
  5621.  character set'' (which is the same as ASCII).  This standard permits the
  5622.  substitution only of the actual characters shown in ISO/IEC 646 {1}:
  5623.  currency sign for the dollar sign and pound sign for the number sign.
  5624.  This document uses the latter names and their symbols, but it is valid
  5625.  for an implementation to accept, for instance, the pound sign () as a
  5626.  comment character in the shell, if that is what the locale's character
  5627.  set uses instead of the number sign (#).  Other variation of national
  5628.  currency symbols are not allowed, per the request of the WG15 POSIX
  5629.  working group.
  5630.  
  5631.  The term _s_t_r_e_a_m is not related to System V's STREAMS communications
  5632.  facility; it is derived from historical UNIX system usage and has been
  5633.  made official by the C Standard {7}.  The POSIX.2 standard makes no
  5634.  differentiation between C's _t_e_x_t _s_t_r_e_a_m and _b_i_n_a_r_y _s_t_r_e_a_m.
  5635.  
  5636.  The formula used in the POSIX.1 {8} definition of _s_e_c_o_n_d_s _s_i_n_c_e _t_h_e _E_p_o_c_h  1
  5637.  is not perfect in all cases.  See the related rationale in POSIX.1 {8}.    1
  5638.  
  5639.  END_RATIONALE                                                              1
  5640.  
  5641.  
  5642.  
  5643.  
  5644.  
  5645.  
  5646.  
  5647.  
  5648.  
  5649.  
  5650.  
  5651.  
  5652.  
  5653.  
  5654.  
  5655.  
  5656.  
  5657.  
  5658.  
  5659.  
  5660.  
  5661.  
  5662.  
  5663.  
  5664.  
  5665.  
  5666.  
  5667.                Copyright c 1991 IEEE.  All rights reserved.
  5668.       This is an unapproved IEEE Standards Draft, subject to change.
  5669.  
  5670.  
  5671.  
  5672.  
  5673.  
  5674.  56                                 2 Terminology and General Requirements
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5681.  
  5682.  2.2.3  Abbreviations
  5683.  
  5684.  For the purposes of this standard, the following abbreviations apply:
  5685.  
  5686.  
  5687.  2.2.3.1  C Standard:  ISO/IEC 9899: ..., _I_n_f_o_r_m_a_t_i_o_n _p_r_o_c_e_s_s_i_n_g _s_y_s_t_e_m_s-
  5688.  -_P_r_o_g_r_a_m_m_i_n_g _l_a_n_g_u_a_g_e_s--_C {7}.
  5689.  
  5690.  2.2.3.2  ERE:  An Extended Regular Expression, as defined in 2.8.4.
  5691.  
  5692.  
  5693.  2.2.3.3  LC_*:  An abbreviation used to represent all of the environment
  5694.  variables named in 2.6 whose names begin with the characters ``LC_''.
  5695.  
  5696.  2.2.3.4  POSIX.1:  ISO/IEC 9945-1: 1990:  _I_n_f_o_r_m_a_t_i_o_n _t_e_c_h_n_o_l_o_g_y--
  5697.  _P_o_r_t_a_b_l_e _O_p_e_r_a_t_i_n_g _S_y_s_t_e_m _I_n_t_e_r_f_a_c_e (_P_O_S_I_X)--_P_a_r_t _1: _S_y_s_t_e_m _A_p_p_l_i_c_a_t_i_o_n
  5698.  _P_r_o_g_r_a_m _I_n_t_e_r_f_a_c_e (_A_P_I) [_C _L_a_n_g_u_a_g_e] {8}.
  5699.  
  5700.  
  5701.  2.2.3.5  POSIX.2:  This standard.
  5702.  
  5703.  2.2.3.6  RE [BRE]:  A Basic Regular Expression, as defined in 2.8.3.
  5704.  
  5705.  
  5706.  
  5707.  
  5708.  
  5709.  
  5710.  
  5711.  
  5712.  
  5713.  
  5714.  
  5715.  
  5716.  
  5717.  
  5718.  
  5719.  
  5720.  
  5721.  
  5722.  
  5723.  
  5724.  
  5725.  
  5726.  
  5727.  
  5728.  
  5729.  
  5730.  
  5731.  
  5732.  
  5733.                Copyright c 1991 IEEE.  All rights reserved.
  5734.       This is an unapproved IEEE Standards Draft, subject to change.
  5735.  
  5736.  
  5737.  
  5738.  
  5739.  
  5740.  2.2 Definitions                                                        57
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5747.  
  5748.  2.3  Built-in Utilities
  5749.  
  5750.  Any of the standard utilities may be implemented as _r_e_g_u_l_a_r _b_u_i_l_t-_i_n
  5751.  utilities within the command language interpreter.  This is usually done
  5752.  to increase the performance of frequently-used utilities or to achieve
  5753.  functionality that would be more difficult in a separate environment.
  5754.  The utilities named in Table 2-2 are frequently provided in built-in
  5755.  form.  All of the utilities named in the table have special properties in
  5756.  terms of command search order within the shell, as described in 3.9.1.1.
  5757.  
  5758.  
  5759.                  Table 2-2  -  Regular Built-in Utilities
  5760.  __________________________________________________________________________________________________________________________________________________
  5761.  
  5762.               cd        false     kill      true      wait
  5763.               command   getopts   read      umask
  5764.  __________________________________________________________________________________________________________________________________________________
  5765.  
  5766.  
  5767.  However, all of the standard utilities, including the regular built-ins
  5768.  in the table, but not the special built-ins described in 3.14, shall be
  5769.  implemented in a manner so that they can be accessed via the POSIX.1 {8}
  5770.  _e_x_e_c family of functions (if the underlying operating system provides the
  5771.  services of such a family to application programs) and can be invoked
  5772.  directly by those standard utilities that require it (env, find, nohup,
  5773.  xargs).
  5774.  
  5775.  Since versions shall be provided for all utilities except for those
  5776.  listed previously, an application running on a system that conforms to
  5777.  both POSIX.1 {8} and Section 7 of this standard can use the _e_x_e_c family
  5778.  of functions, in addition to the shell command interface in 7.1 [such as
  5779.  the _s_y_s_t_e_m() and _p_o_p_e_n() functions in the C binding] defined by this
  5780.  standard, to execute any of these utilities.
  5781.  
  5782.  BEGIN_RATIONALE
  5783.  
  5784.  
  5785.  2.3.1  Built-in Utilities Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  5786.         _P_1_0_0_3._2)
  5787.  
  5788.  In earlier drafts, the table of built-ins implied two things to a
  5789.  conforming application:  these may be built-ins and these need not be
  5790.  executable.  The second implication has now been removed and all
  5791.  utilities can be _e_x_e_c-ed.  There is no requirement that these be actually
  5792.  built into the shell itself, but many shells will want to do so because
  5793.  3.9.1.1 requires that they be found prior to the PATH search.  The shell
  5794.  could satisfy its requirements by keeping a list of the names and
  5795.  directly accessing the file-system versions regardless of PATH.
  5796.  Providing all of the required functionality for those such as cd or read
  5797.  
  5798.  
  5799.                Copyright c 1991 IEEE.  All rights reserved.
  5800.       This is an unapproved IEEE Standards Draft, subject to change.
  5801.  
  5802.  
  5803.  
  5804.  
  5805.  
  5806.  58                                 2 Terminology and General Requirements
  5807.  
  5808.  
  5809.  
  5810.  
  5811.  
  5812.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5813.  
  5814.  would be more difficult.
  5815.  
  5816.  There were originally three justifications for allowing the omission of
  5817.  _e_x_e_c-able versions:
  5818.  
  5819.      (1)  This would require wasting space in the file system, at the
  5820.           expense of very small systems.  However, it has been pointed out
  5821.           that all nine in the table can be provided with nine links to a
  5822.           single-line shell script:
  5823.  
  5824.                 $0 "$@"
  5825.  
  5826.      (2)  There is no sense in requiring invocation of utilities like cd
  5827.           because they have no value outside the shell environment or
  5828.           cannot be useful in a child process.  However, counter-examples
  5829.           always seemed to be available for even the strangest cases:
  5830.  
  5831.                 find . -type d -exec cd {} ; -exec foo {} ;
  5832.                     (which invokes foo on accessible directories)
  5833.  
  5834.                 ps ... | sed ... | xargs kill
  5835.  
  5836.                 find . -exec true ; -a ...
  5837.                     (where true is used for temporary debugging)
  5838.  
  5839.      (3)  It is confusing to have something such as kill that can easily
  5840.           be in the file system in the base standard, but requires built-
  5841.           in status for the UPE (for the % job control job ID notation).
  5842.           It was decided that it was more appropriate to describe the
  5843.           required functionality (rather than the implementation) to the
  5844.           system implementors and let them decide how to satisfy it.
  5845.  
  5846.  On the other hand, there were objections raised during balloting that any
  5847.  distinction like this between utilities was not useful to applications
  5848.  and that the cost to correct it was small.  These arguments were
  5849.  ultimately the most effective.
  5850.  
  5851.  There were varying reasons for including utilities in the table of
  5852.  built-ins:
  5853.  
  5854.     cd, getopts, read, umask, wait
  5855.                 The functionality of these utilities is performed more
  5856.                 simply within the context of the current process.  An
  5857.                 example can be taken from the usage of the cd utility.
  5858.                 The purpose of the utility is to change the working
  5859.                 directory for subsequent operations.  The actions of cd
  5860.                 affect the process in which cd is executed and all
  5861.                 subsequent child processes of that process.  Based on the
  5862.                 POSIX.1 {8} process model, changes in the process
  5863.  
  5864.  
  5865.                Copyright c 1991 IEEE.  All rights reserved.
  5866.       This is an unapproved IEEE Standards Draft, subject to change.
  5867.  
  5868.  
  5869.  
  5870.  
  5871.  
  5872.  2.3 Built-in Utilities                                                 59
  5873.  
  5874.  
  5875.  
  5876.  
  5877.  
  5878.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  5879.  
  5880.                 environment of a child process have no effect on the
  5881.                 parent process.  If the cd utility were executed from a
  5882.                 child process, the working directory change would be
  5883.                 effective only in the child process.  Child processes
  5884.                 initiated subsequent to the child process that executed
  5885.                 the cd utility would not have a changed working directory
  5886.                 relative to the parent process.
  5887.  
  5888.     command     This utility was placed in the table primarily to protect
  5889.                 scripts that are concerned about their PATH being
  5890.                 manipulated.  The ``secure'' shell script example in
  5891.                 4.12.10 would not be possible if a PATH change retrieved
  5892.                 an alien version of command.  (An alternative would have
  5893.                 been to implement getconf as a built-in, but it was felt
  5894.                 that it carried too many changing configuration strings to
  5895.                 require in the shell.)
  5896.  
  5897.     kill        Since common extensions to kill (including the planned
  5898.                 User Portability Extension) provide optional job control
  5899.                 functionality using shell notation (%1, %2, etc.), some
  5900.                 implementations would find it extremely difficult to
  5901.                 provide this outside the shell.
  5902.  
  5903.     true, false
  5904.                 These are in the table as a courtesy to programmers who
  5905.                 wish to use the ``while true'' shell construct without
  5906.                 protecting true from PATH searches.  (It is acknowledged
  5907.                 that ``while :'' also works, but the idiom with true is
  5908.                 historically pervasive.)
  5909.  
  5910.  All utilities, including those in the table, are accessible via the
  5911.  functions in 7.1.1 or 7.1.2 [such as _s_y_s_t_e_m() or _p_o_p_e_n()].  There are
  5912.  situations where the return functionality of _s_y_s_t_e_m() and _p_o_p_e_n() is not
  5913.  desirable.  Applications that require the exit status of the invoked
  5914.  utility will not be able to use _s_y_s_t_e_m() or _p_o_p_e_n(), since the exit
  5915.  status returned is that of the command language interpreter rather than
  5916.  that of the invoked utility.  The alternative for such applications is
  5917.  the use of the _e_x_e_c family.  (The text concerning conformance to
  5918.  POSIX.1 {8} was included because where _e_x_e_c is not provided in the
  5919.  underlying system, there is no way to require that utilities be _e_x_e_c-
  5920.  able).
  5921.  
  5922.  END_RATIONALE
  5923.  
  5924.  
  5925.  
  5926.  
  5927.  
  5928.  
  5929.  
  5930.  
  5931.                Copyright c 1991 IEEE.  All rights reserved.
  5932.       This is an unapproved IEEE Standards Draft, subject to change.
  5933.  
  5934.  
  5935.  
  5936.  
  5937.  
  5938.  60                                 2 Terminology and General Requirements
  5939.  
  5940.  
  5941.  
  5942.  
  5943.  
  5944.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  5945.  
  5946.  2.4  Character Set
  5947.  
  5948.  Conforming implementations shall support one or more coded character
  5949.  sets.  Each supported coded character set shall include the _p_o_r_t_a_b_l_e
  5950.  _c_h_a_r_a_c_t_e_r _s_e_t specified in Table 2-3.  The table defines the characters
  5951.  in the portable character set and the corresponding symbolic character
  5952.  names used to identify each character in a character set description
  5953.  file.  The names are chosen to correspond closely with character names
  5954.  defined in other international standards.  The table contains more than
  5955.  one symbolic character name for characters whose traditional name differs
  5956.  from the chosen name.
  5957.  
  5958.  This standard places only the following requirements on the encoded
  5959.  values of the characters in the portable character set:
  5960.  
  5961.      (1)  If the encoded values associated with each member of the
  5962.           portable character set are not invariant across all locales
  5963.           supported by the implementation, the results achieved by an
  5964.           application accessing those locales are unspecified.
  5965.  
  5966.      (2)  The encoded values associated with the digits '0' to '9' shall
  5967.           be such that the value of each character after '0' shall be one
  5968.           greater than the value of the previous character.
  5969.  
  5970.      (3)  A null character, NUL, which has all bits set to zero, shall be
  5971.           in the set of characters.
  5972.  
  5973.  Conforming implementations shall support certain character and character
  5974.  set attributes, as defined in 2.5.1.
  5975.  
  5976.  
  5977.  2.4.1  Character Set Description File
  5978.  
  5979.  Implementations shall provide a character set description file for at
  5980.  least one coded character set supported by the implementation.  These
  5981.  files are referred to elsewhere in this standard as _c_h_a_r_m_a_p files.  It is
  5982.  implementation defined whether or not users or applications can provide
  5983.  additional character set description files.  If such a capability is
  5984.  supported, the system documentation shall describe the rules for the
  5985.  creation of such files.
  5986.  
  5987.  Each character set description file shall define characteristics for the
  5988.  coded character set and the encoding for the characters specified in
  5989.  Table 2-3, and may define encoding for additional characters supported by
  5990.  the implementation.  Other information about the coded character set may
  5991.  also be in the file.  Coded character set character values shall be
  5992.  defined using symbolic character names followed by character encoding
  5993.  values.
  5994.  
  5995.  
  5996.  
  5997.                Copyright c 1991 IEEE.  All rights reserved.
  5998.       This is an unapproved IEEE Standards Draft, subject to change.
  5999.  
  6000.  
  6001.  
  6002.  
  6003.  
  6004.  2.4 Character Set                                                      61
  6005.  
  6006.  
  6007.  
  6008.  
  6009.  
  6010.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6011.  
  6012.  
  6013.               Table 2-3  -  Character Set and Symbolic Names
  6014.  __________________________________________________________________________________________________________________________________________________
  6015.       Symbolic                  Symbolic                  Symbolic
  6016.         Name        Glyph         Name         Glyph        Name         Glyph
  6017.  _____________________________________________________________________________
  6018.  
  6019.  <NUL>                   <colon>                 :  <circumflex>           ^
  6020.  <alert>                 <semicolon>             ;  <circumflex-accent>    ^
  6021.  <backspace>             <less-than-sign>        <  <underscore>           _
  6022.  <tab>                   <equals-sign>           =  <low-line>             _
  6023.  <newline>               <greater-than-sign>     >  <grave-accent>         `
  6024.  <vertical-tab>          <question-mark>         ?  <a>                    a
  6025.  <form-feed>             <commercial-at>         @  <b>                    b
  6026.  <carriage-return>       <A>                     A  <c>                    c
  6027.  <space>                 <B>                     B  <d>                    d
  6028.  <exclamation-mark>   !  <C>                     C  <e>                    e
  6029.  <quotation-mark>     "  <D>                     D  <f>                    f
  6030.  <number-sign>        #  <E>                     E  <g>                    g
  6031.  <dollar-sign>        $  <F>                     F  <h>                    h
  6032.  <percent-sign>       %  <G>                     G  <i>                    i
  6033.  <ampersand>          &  <H>                     H  <j>                    j
  6034.  <apostrophe>         '  <I>                     I  <k>                    k
  6035.  <left-parenthesis>   (  <J>                     J  <l>                    l
  6036.  <right-parenthesis>  )  <K>                     K  <m>                    m
  6037.  <asterisk>           *  <L>                     L  <n>                    n
  6038.  <plus-sign>          +  <M>                     M  <o>                    o
  6039.  <comma>              ,  <N>                     N  <p>                    p
  6040.  <hyphen>             -  <O>                     O  <q>                    q
  6041.  <hyphen-minus>       -  <P>                     P  <r>                    r
  6042.  <period>             .  <Q>                     Q  <s>                    s
  6043.  <full-stop>          .  <R>                     R  <t>                    t
  6044.  <slash>              /  <S>                     S  <u>                    u
  6045.  <solidus>            /  <T>                     T  <v>                    v
  6046.  <zero>               0  <U>                     U  <w>                    w
  6047.  <one>                1  <V>                     V  <x>                    x
  6048.  <two>                2  <W>                     W  <y>                    y
  6049.  <three>              3  <X>                     X  <z>                    z
  6050.  <four>               4  <Y>                     Y  <left-brace>           {
  6051.  <five>               5  <Z>                     Z  <left-curly-bracket>   {
  6052.  <six>                6  <left-square-bracket>   [  <vertical-line>        |
  6053.  <seven>              7  <backslash>             \  <right-brace>          }
  6054.  <eight>              8  <reverse-solidus>       \  <right-curly-bracket>  }
  6055.  <nine>               9  <right-square-bracket>  ]  <tilde>                ~
  6056.  __________________________________________________________________________________________________________________________________________________
  6057.  
  6058.  
  6059.  Each symbolic name specified in Table 2-3 shall be included in the file
  6060.  and shall be mapped to a unique encoding value (except for those symbolic  1
  6061.  names that are shown with identical glyphs).  If the control characters    1
  6062.  
  6063.                Copyright c 1991 IEEE.  All rights reserved.
  6064.       This is an unapproved IEEE Standards Draft, subject to change.
  6065.  
  6066.  
  6067.  
  6068.  
  6069.  
  6070.  62                                 2 Terminology and General Requirements
  6071.  
  6072.  
  6073.  
  6074.  
  6075.  
  6076.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6077.  
  6078.  commonly associated with the symbolic names in Table 2-4 are supported by
  6079.  the implementation, the symbolic names and their corresponding encoding
  6080.  values shall be included in the file.  Some of the values associated with  1
  6081.  the symbolic names in this table also may be contained in Table 2-3.       1
  6082.  
  6083.  
  6084.                     Table 2-4  -  Control Character Set
  6085.  __________________________________________________________________________________________________________________________________________________
  6086.  
  6087.                <ACK>   <DC2>   <ENQ>   <FS>    <IS4>   <SOH>                1
  6088.                <BEL>   <DC3>   <EOT>   <GS>    <LF>    <STX>                1
  6089.                <BS>    <DC4>   <ESC>   <HT>    <NAK>   <SUB>                1
  6090.                <CAN>   <DEL>   <ETB>   <IS1>   <RS>    <SYN>                1
  6091.                <CR>    <DLE>   <ETX>   <IS2>   <SI>    <US>                 1
  6092.                <DC1>   <EM>    <FF>    <IS3>   <SO>    <VT>                 1
  6093.  __________________________________________________________________________________________________________________________________________________
  6094.  
  6095.  
  6096.  The following declarations can precede the character definitions.  Each
  6097.  shall consist of the symbol shown in the following list, starting in
  6098.  column 1, including the surrounding brackets, followed by one of more
  6099.  <blank>s, followed by the value to be assigned to the symbol.
  6100.  
  6101.     <code_set_name>     The name of the coded character set for which the
  6102.                         character set description file is defined.  The
  6103.                         characters of the name shall be taken from the set
  6104.                         of characters with visible glyphs defined in        1
  6105.                         Table 2-3.                                          1
  6106.  
  6107.     <mb_cur_max>        The maximum number of bytes in a multibyte
  6108.                         character.  This shall default to 1.
  6109.  
  6110.     <mb_cur_min>        An unsigned positive integer value that shall
  6111.                         define the minimum number of bytes in a character
  6112.                         for the encoded character set.  The value shall be
  6113.                         less than or equal to mb_cur_max.  If not
  6114.                         specified, the minimum number shall be equal to
  6115.                         mb_cur_max.
  6116.  
  6117.     <escape_char>       The escape character used to indicate that the
  6118.                         characters following shall be interpreted in a
  6119.                         special way, as defined later in this subclause.
  6120.                         This shall default to backslash (\), which is the
  6121.                         character glyph used in all the following text and
  6122.                         examples, unless otherwise noted.
  6123.  
  6124.     <comment_char>      The character, that when placed in column 1 of a
  6125.                         charmap line, is used to indicate that the line
  6126.                         shall be ignored.  The default character shall be
  6127.  
  6128.  
  6129.                Copyright c 1991 IEEE.  All rights reserved.
  6130.       This is an unapproved IEEE Standards Draft, subject to change.
  6131.  
  6132.  
  6133.  
  6134.  
  6135.  
  6136.  2.4 Character Set                                                      63
  6137.  
  6138.  
  6139.  
  6140.  
  6141.  
  6142.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6143.  
  6144.                         the number-sign (#).
  6145.  
  6146.  The character set mapping definitions shall be all the lines immediately
  6147.  following an identifier line containing the string CHARMAP starting in
  6148.  column 1, and preceding a trailer line containing the string END CHARMAP
  6149.  starting in column 1.  Empty lines and lines containing a comment_char in
  6150.  the first column shall be ignored.  Each noncomment line of the character
  6151.  set mapping definition (i.e., between the CHARMAP and END CHARMAP lines
  6152.  of the file) shall be in either of two forms:
  6153.  
  6154.        "%s %s %s\n", <_s_y_m_b_o_l_i_c-_n_a_m_e>, <_e_n_c_o_d_i_n_g>, <_c_o_m_m_e_n_t_s>
  6155.  
  6156.  or
  6157.  
  6158.        "%s...%s %s %s\n", <_s_y_m_b_o_l_i_c-_n_a_m_e>, <_s_y_m_b_o_l_i_c-_n_a_m_e>, <_e_n_c_o_d_i_n_g>,
  6159.        <_c_o_m_m_e_n_t_s>
  6160.  
  6161.  In the first format, the line in the character set mapping definition
  6162.  defines a single symbolic name and a corresponding encoding.  A symbolic
  6163.  name is one or more characters from the set shown with visible glyphs in
  6164.  Table 2-3, enclosed between angle brackets.  A character following an
  6165.  escape character shall be interpreted as itself; for example, the
  6166.  sequence ``<\\\>>'' represents the symbolic name ``\>'' enclosed between
  6167.  angle brackets.
  6168.  
  6169.  In the second format, the line in the character set mapping definition
  6170.  defines a range of one or more symbolic names.  In this form, the
  6171.  symbolic names shall consist of zero or more nonnumeric characters from
  6172.  the set shown with visible glyphs in Table 2-3, followed by an integer
  6173.  formed by one or more decimal digits.  The characters preceding the
  6174.  integer shall be identical in the two symbolic names, and the integer
  6175.  formed by the digits in the second symbolic name shall be equal to or
  6176.  greater than the integer formed by the digits in the first name.  This
  6177.  shall be interpreted as a series of symbolic names formed from the common
  6178.  part and each of the integers between the first and the second integer,
  6179.  inclusive.  As an example, <j0101>...<j0104> is interpreted as the
  6180.  symbolic names <j0101>, <j0102>, <j0103>, and <j0104>, in that order.
  6181.  
  6182.  A character set mapping definition line shall exist for all symbolic
  6183.  names specified in Table 2-3, and shall define the coded character value
  6184.  that corresponds with the character glyph indicated in the table, or the
  6185.  coded character value that corresponds with the control character
  6186.  symbolic name.  If the control characters commonly associated with the
  6187.  symbolic names in Table 2-4 are supported by the implementation, the
  6188.  symbolic name and the corresponding encoding value shall be included in
  6189.  the file.  Additional unique symbolic names may be included.  A coded
  6190.  character value can be represented by more than one symbolic name.
  6191.  
  6192.  
  6193.  
  6194.  
  6195.                Copyright c 1991 IEEE.  All rights reserved.
  6196.       This is an unapproved IEEE Standards Draft, subject to change.
  6197.  
  6198.  
  6199.  
  6200.  
  6201.  
  6202.  64                                 2 Terminology and General Requirements
  6203.  
  6204.  
  6205.  
  6206.  
  6207.  
  6208.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6209.  
  6210.  The encoding part shall be expressed as one (for single-byte character     1
  6211.  values) or more concatenated decimal, octal, or hexadecimal constants in   1
  6212.  the following formats:
  6213.  
  6214.        "%cd%d", <_e_s_c_a_p_e__c_h_a_r>, <_d_e_c_i_m_a_l _b_y_t_e _v_a_l_u_e>
  6215.  
  6216.        "%cx%x", <_e_s_c_a_p_e__c_h_a_r>, <_h_e_x_a_d_e_c_i_m_a_l _b_y_t_e _v_a_l_u_e>
  6217.  
  6218.        "%c%o", <_e_s_c_a_p_e__c_h_a_r>, <_o_c_t_a_l _b_y_t_e _v_a_l_u_e>
  6219.  
  6220.  Decimal constants shall be represented by two or three decimal digits,     2
  6221.  preceded by the escape character and the lowercase letter d; for example,  2
  6222.  \d05, \d97, or \d143.  Hexadecimal constants shall be represented by two   2
  6223.  hexadecimal digits, preceded by the escape character and the lowercase     2
  6224.  letter x; for example, \x05, \x61, or \x8f.  Octal constants shall be      2
  6225.  represented by two or three octal digits, preceded by the escape           2
  6226.  character; for example, \05, \141, or \217.  In a portable charmap file,   2
  6227.  each constant shall represent an 8-bit byte.  Implementations supporting   2
  6228.  other byte sizes may allow constants to represent values larger than       2
  6229.  those that can be represented in 8-bit bytes, and to allow additional      2
  6230.  digits in constants.  When constants are concatenated for multibyte        2
  6231.  character values, they shall be of the same type, and interpreted in byte  2
  6232.  order from left to right.  The manner in which constants are represented   2
  6233.  in the character is implementation defined.  Omitting bytes from a         2
  6234.  multibyte character definition produces undefined results.                 2
  6235.  
  6236.  In lines defining ranges of symbolic names, the encoded value is the
  6237.  value for the first symbolic name in the range (the symbolic name
  6238.  preceding the ellipsis).  Subsequent symbolic names defined by the range
  6239.  shall have encoding values in increasing order.  For example, the line
  6240.  
  6241.        <j0101>...<j0104>       \d129\d254
  6242.  
  6243.  shall be interpreted as
  6244.  
  6245.        <j0101>                 \d129\d254
  6246.        <j0102>                 \d129\d255
  6247.        <j0103>                 \d130\d0
  6248.        <j0104>                 \d130\d1
  6249.  
  6250.  The comment is optional.
  6251.  
  6252.  For the interpretation of the dollar-sign and the number-sign, see
  6253.  2.2.2.37 and 2.2.2.93.
  6254.  
  6255.  BEGIN_RATIONALE
  6256.  
  6257.  
  6258.  
  6259.  
  6260.  
  6261.                Copyright c 1991 IEEE.  All rights reserved.
  6262.       This is an unapproved IEEE Standards Draft, subject to change.
  6263.  
  6264.  
  6265.  
  6266.  
  6267.  
  6268.  2.4 Character Set                                                      65
  6269.  
  6270.  
  6271.  
  6272.  
  6273.  
  6274.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6275.  
  6276.  2.4.2  Character Set Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  6277.  
  6278.  The portable character set is listed in full so there is no dependency on
  6279.  the ISO/IEC 646 {1} (or historically ASCII) encoded character set,
  6280.  although the set is identical to the characters defined in the
  6281.  International Reference Version of ISO/IEC 646 {1}.
  6282.  
  6283.  This standard poses no requirement that multiple character sets or code
  6284.  sets be supported, leaving this as a marketing differentiation for
  6285.  implementors.  Although multiple _c_h_a_r_m_a_p files are supported, it is the
  6286.  responsibility of the implementation to provide the file(s); if only one
  6287.  is provided, only that one will be accessible using the localedef
  6288.  utility's -f option (although in the case of just one file on the system,
  6289.  -f is not useful).
  6290.  
  6291.  The statement about invariance in code sets for the portable character
  6292.  set is worded as it is to avoid precluding implementations where multiple
  6293.  incompatible code sets are available (say, ASCII and EBCDIC).  The
  6294.  standard utilities cannot be expected to produce predictable results if
  6295.  they access portable characters that vary on the same implementation.
  6296.  
  6297.  The character set description file provides:
  6298.  
  6299.      - the capability to describe character set attributes (such as
  6300.        collation order or character classes) independent of character set
  6301.        encoding, and using only the characters in the portable character
  6302.        set.  This makes it possible to create ``generic'' localedef source
  6303.        files for all code sets that share the portable character set (such
  6304.        as the ISO 8859 family or IBM Extended ASCII).
  6305.  
  6306.      - standardized symbolic names for all characters in the portable
  6307.        character set, making it possible to refer to any such character
  6308.        regardless of encoding.
  6309.  
  6310.  Implementations are free to describe more than one code set in a
  6311.  character set description file, as long as only one encoding exists for
  6312.  the characters in Table 2-3.  For example, if an implementation defines
  6313.  ISO 8859-1 {5} as the primary code set, and ISO 8859-2 {6} as an
  6314.  alternate set, with each character from the alternate code set preceded
  6315.  in data by a shift code, a character set description file could contain a
  6316.  complete description of the primary set and those characters from the
  6317.  secondary that are not identical, the encoding of the latter including
  6318.  the shift code.
  6319.  
  6320.  Implementations are free to choose their own symbolic names, as long as
  6321.  the names identified by this standard are also defined; this provides
  6322.  support for already existing ``character names.''
  6323.  
  6324.  
  6325.  
  6326.  
  6327.                Copyright c 1991 IEEE.  All rights reserved.
  6328.       This is an unapproved IEEE Standards Draft, subject to change.
  6329.  
  6330.  
  6331.  
  6332.  
  6333.  
  6334.  66                                 2 Terminology and General Requirements
  6335.  
  6336.  
  6337.  
  6338.  
  6339.  
  6340.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6341.  
  6342.  The names selected for the members of the portable character set follow
  6343.  the ISO 8859 {5} and the ISO/IEC 10646 {B11} standards.  However, several
  6344.  commonly used UNIX system names occur as synonyms in the list:
  6345.  
  6346.      - The traditional UNIX system names are used for control characters.
  6347.  
  6348.      - The word ``slash'' is in addition to ``solidus.''                    1
  6349.  
  6350.      - The word ``backslash'' is in addition to ``reverse-solidus.''        1
  6351.  
  6352.      - The word ``hyphen'' in addition to ``hyphen-minus.''
  6353.  
  6354.      - The word ``period'' in addition to ``full-stop.''
  6355.  
  6356.      - For the digits, the word ``digit'' is eliminated.
  6357.  
  6358.      - For letters, the words ``Latin Capital Letter'' and ``Latin Small
  6359.        Letter'' are eliminated.
  6360.  
  6361.      - The words ``left-brace'' and ``right-brace'' in addition to
  6362.        ``left-curly-bracket'' and ``right-curly-bracket.''
  6363.  
  6364.      - The names of the digits are preferred over the numbers, to avoid
  6365.        possible confusion between ``0'' and ``O'', and between ``1'' and
  6366.        ``l'' (one and the letter ell).
  6367.  
  6368.  The names for the control characters in Table 2-4 were taken from
  6369.  ISO 4873 {4}.
  6370.  
  6371.  The charmap file was introduced to resolve problems with the portability
  6372.  of, especially, localedef sources.  This standard assumes that the         1
  6373.  portable character set is constant across all locales, but does not        1
  6374.  prohibit implementations from supporting two incompatible codings, such    1
  6375.  as both ASCII and EBCDIC.  Such ``dual-support'' implementations should    1
  6376.  have all charmaps and localedef sources encoded using one portable         1
  6377.  character set, in effect ``cross-compiling'' for the other environment.    1
  6378.  Naturally, charmaps (and localedef sources) are only portable without      1
  6379.  transformation between systems using the same encodings for the portable   1
  6380.  character set.  They can, however, be transformed between two sets using   1
  6381.  only a subset of the actual characters (the portable set).  However, the   1
  6382.  particular coded character set used for an application or an               1
  6383.  implementation does not necessarily imply different characteristics or
  6384.  collation:  on the contrary, these attributes should in many cases be
  6385.  identical, regardless of code set.  The charmap provides the capability
  6386.  to define a common locale definition for multiple code sets (the same
  6387.  localedef source can be used for code sets with different extended
  6388.  characters; the ability in the charmap to define ``empty'' names allows
  6389.  for characters missing in certain code sets).
  6390.  
  6391.  
  6392.  
  6393.                Copyright c 1991 IEEE.  All rights reserved.
  6394.       This is an unapproved IEEE Standards Draft, subject to change.
  6395.  
  6396.  
  6397.  
  6398.  
  6399.  
  6400.  2.4 Character Set                                                      67
  6401.  
  6402.  
  6403.  
  6404.  
  6405.  
  6406.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6407.  
  6408.  In addition, several implementors have expressed an interest in using the
  6409.  charmap concept to provide the information required for support of
  6410.  multiple character sets.  Examples of such information is encoding
  6411.  mechanism, string parsing rules, default font information, etc.  Such
  6412.  extensions are not described here.
  6413.  
  6414.  The <escape_char> declaration was added at the request of the
  6415.  international community to ease the creation of portable _c_h_a_r_m_a_p files on
  6416.  terminals not implementing the default backslash escape.  (This approach
  6417.  was adopted because this is a new interface invented by POSIX.2.
  6418.  Historical interfaces, such as the shell command language and awk, have
  6419.  not been modified to accommodate this type of terminal.)  The
  6420.  <comment_char> declaration was added at the request of the international
  6421.  community to eliminate the potential confusion between the number sign
  6422.  and the pound sign.
  6423.  
  6424.  The octal number notation with no leading zero required was selected to    1
  6425.  match those of awk and tr and is consistent with that used by localedef.   1
  6426.  To avoid confusion between an octal constant and the backreferences used   1
  6427.  in localedef source, the octal, hexadecimal, and decimal constants must    1
  6428.  contain at least two digits.  As single-digit constants are relatively     1
  6429.  rare, this should not impose any significant hardship.  Each of the        1
  6430.  constants includes ``two or more'' digits to account for systems in which  1
  6431.  the byte size is larger than eight bits.  For example, a Unicode system    1
  6432.  that has defined 16-bit bytes may require six octal, four hexadecimal,     1
  6433.  and five decimal digits.                                                   1
  6434.  
  6435.  The decimal notation is supported because some newer international
  6436.  standards define character values in decimal, rather than in the old
  6437.  column/row notation.
  6438.  
  6439.  The charmap identifies the coded character sets supported by an
  6440.  implementation.  At least one charmap must be provided, but no
  6441.  implementation is required to provide more than one.  Likewise,
  6442.  implementations can allow users to generate new charmaps (for instance
  6443.  for a new version of the 8859 family of coded character sets), but does
  6444.  not have to do so.  If users are allowed to create new charmaps, the
  6445.  system documentation must describe the rules that apply (for instance:
  6446.  ``only coded character sets that are supersets of ISO/IEC 646 {1} IRV, no
  6447.  multibyte characters, etc.'')
  6448.  
  6449.  END_RATIONALE
  6450.  
  6451.  
  6452.  
  6453.  
  6454.  
  6455.  
  6456.  
  6457.  
  6458.  
  6459.                Copyright c 1991 IEEE.  All rights reserved.
  6460.       This is an unapproved IEEE Standards Draft, subject to change.
  6461.  
  6462.  
  6463.  
  6464.  
  6465.  
  6466.  68                                 2 Terminology and General Requirements
  6467.  
  6468.  
  6469.  
  6470.  
  6471.  
  6472.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6473.  
  6474.  2.5  Locale
  6475.  
  6476.  A _l_o_c_a_l_e is the definition of the subset of a user's environment that
  6477.  depends on language and cultural conventions.  It is made up from one or
  6478.  more categories.  Each category is identified by its name and controls
  6479.  specific aspects of the behavior of components of the system.  Category
  6480.  names correspond to the following environment variable names:
  6481.  
  6482.     LC_CTYPE         Character classification and case conversion.
  6483.  
  6484.     LC_COLLATE       Collation order.
  6485.  
  6486.     LC_TIME          Date and time formats.
  6487.  
  6488.     LC_NUMERIC       Numeric, nonmonetary formatting.
  6489.  
  6490.     LC_MONETARY      Monetary formatting.
  6491.  
  6492.     LC_MESSAGES      Formats of informative and diagnostic messages and
  6493.                      interactive responses.
  6494.  
  6495.  Conforming implementations shall provide the standard utilities and the    1
  6496.  interfaces in Annex B (if that option is supported) with the capability    1
  6497.  to modify their behavior based on the current locale, as defined in the    1
  6498.  Environment Variables subclause for each utility and interface.            1
  6499.  
  6500.  Locales other than those supplied by the implementation can be created
  6501.  via the localedef utility (see 4.35), provided that the
  6502.  {POSIX2_LOCALEDEF} symbol is defined on the system; see 2.13.2.
  6503.  Otherwise, only the implementation-provided locale(s) can be used.  The
  6504.  input to the utility is described in 2.5.2.  The value that shall be used
  6505.  to specify a locale when using environment variables shall be the string
  6506.  specified as the _n_a_m_e operand to the localedef utility when the locale
  6507.  was created.  The strings "C" and "POSIX" are reserved as identifiers for
  6508.  the POSIX Locale (see 2.5.1.)  When the value of a locale environment
  6509.  variable begins with a slash (/), it shall be interpreted as the pathname
  6510.  of the locale definition.  If the value of the locale value does not
  6511.  begin with a slash, the mechanism used to locate the locale is
  6512.  implementation defined.
  6513.  
  6514.  If different character sets are used by the locale categories, the
  6515.  results achieved by an application utilizing these categories is
  6516.  undefined.  Likewise, if different code sets are used for the data being
  6517.  processed by interfaces whose behavior is dependent on the current
  6518.  locale, or the code set is different from the code set assumed when the
  6519.  locale was created, the result is also undefined.
  6520.  
  6521.  BEGIN_RATIONALE
  6522.  
  6523.  
  6524.  
  6525.                Copyright c 1991 IEEE.  All rights reserved.
  6526.       This is an unapproved IEEE Standards Draft, subject to change.
  6527.  
  6528.  
  6529.  
  6530.  
  6531.  
  6532.  2.5 Locale                                                             69
  6533.  
  6534.  
  6535.  
  6536.  
  6537.  
  6538.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6539.  
  6540.  2.5.0.1  Locale Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  6541.  
  6542.  The description of locales is based on work performed in the UniForum
  6543.  Technical Committee Subcommittee on Internationalization.  Wherever
  6544.  appropriate, keywords were taken from the C Standard {7} or the _X/_O_p_e_n
  6545.  _P_o_r_t_a_b_i_l_i_t_y _G_u_i_d_e {B31}.
  6546.  
  6547.  The value that shall be used to specify a locale when using environment
  6548.  variables is the name specified as the _n_a_m_e operand to the localedef
  6549.  utility when the locale was created.  This provides a verifiable method
  6550.  to create and invoke a locale.
  6551.  
  6552.  The ``object'' definitions need not be portable, as long as ``source''
  6553.  definitions are.  Strictly speaking, ``source'' definitions are portable
  6554.  only between implementations using the same character set(s).  Such
  6555.  ``source'' definitions can, if they use symbolic names only, easily be
  6556.  ported between systems using different code sets as long as the
  6557.  characters in the portable character set (Table 2-3) have common values
  6558.  between the code sets; this is frequently the case in historical
  6559.  implementations.  Of course, this requires that the symbolic names used
  6560.  for characters outside the portable character set are identical between
  6561.  character sets.  The definition of symbolic names for characters is
  6562.  outside the scope of this standard, but is certainly within the scope of
  6563.  other standards organizations.  When such names are standardized, future
  6564.  versions of POSIX.2 should require the use of these names.
  6565.  
  6566.  Applications can select the desired locale by invoking the _s_e_t_l_o_c_a_l_e()
  6567.  function (or equivalent) with the appropriate value.  If the function is
  6568.  invoked with an empty string, the value of the corresponding environment
  6569.  variable is used.  If the environment variable is unset or is set to the
  6570.  empty string, the implementation sets the appropriate environment as
  6571.  defined in 2.6.
  6572.  
  6573.  END_RATIONALE
  6574.  
  6575.  
  6576.  2.5.1  POSIX Locale
  6577.  
  6578.  Conforming implementations shall provide a _P_O_S_I_X _L_o_c_a_l_e.  The behavior of
  6579.  standard utilities in the POSIX Locale shall be as if the locale was
  6580.  defined via the localedef utility with input data from Table 2-5,
  6581.  Table 2-7, Table 2-9, Table 2-10, Table 2-8, and Table 2-11, all in
  6582.  2.5.2.
  6583.  
  6584.  The tables describe the characteristics and behavior of the POSIX Locale
  6585.  for data consisting entirely of characters from the portable character
  6586.  set in Table 2-3 and the control characters in Table 2-4.  For characters
  6587.  other than those in the two tables, the behavior is unspecified.
  6588.  
  6589.  
  6590.  
  6591.                Copyright c 1991 IEEE.  All rights reserved.
  6592.       This is an unapproved IEEE Standards Draft, subject to change.
  6593.  
  6594.  
  6595.  
  6596.  
  6597.  
  6598.  70                                 2 Terminology and General Requirements
  6599.  
  6600.  
  6601.  
  6602.  
  6603.  
  6604.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6605.  
  6606.  The POSIX Locale can be specified by assigning the appropriate
  6607.  environment variables the values "C" or "POSIX".
  6608.  
  6609.  Table 2-5 shows the definition for the LC_CTYPE category.
  6610.  
  6611.  Table 2-7 shows the definition for the LC_COLLATE category.
  6612.  
  6613.  Table 2-8 shows the definition for the LC_MONETARY category.
  6614.  
  6615.  Table 2-9 shows the definition for the LC_NUMERIC category.
  6616.  
  6617.  Table 2-10 shows the definition for the LC_TIME category.
  6618.  
  6619.  Table 2-11 shows the definition for the LC_MESSAGES category.
  6620.  
  6621.  BEGIN_RATIONALE
  6622.  
  6623.  
  6624.  2.5.1.1  POSIX Locale Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  6625.           _P_1_0_0_3._2)
  6626.  
  6627.  The POSIX Locale is equal to the "C" locale, as specified in POSIX.1 {8}.
  6628.  To avoid being classified as a C-language function, the name has been
  6629.  changed to the _P_O_S_I_X _L_o_c_a_l_e; the environment variable value can be either
  6630.  "POSIX", or, for historical reasons, "C".
  6631.  
  6632.  The POSIX definitions mirror the historical UNIX system behavior.
  6633.  
  6634.  The use of symbolic names for characters in the tables does not imply
  6635.  that the POSIX Locale must be described using symbolic character names,
  6636.  but merely that it may be advantageous to do so.
  6637.  
  6638.  Implementations must define a locale as the ``default'' locale, to be
  6639.  invoked when no environment variables are set, or set to the empty
  6640.  string.  This default locale can be the POSIX Locale or any other,
  6641.  implementation-defined locale.  Some implementations may provide
  6642.  facilities for local installation administrators to set the default
  6643.  locale, customizing it for each location.  This standard does not require
  6644.  such a facility.                                                           1
  6645.  
  6646.  END_RATIONALE                                                              1
  6647.  
  6648.  
  6649.  2.5.2  Locale Definition
  6650.  
  6651.  The capability to specify additional locales to those provided by an
  6652.  implementation is optional (see 2.13.2).  If the option is not supported,
  6653.  only implementation-supplied locales are available.  Such locales shall
  6654.  be documented using the format specified in this clause.
  6655.  
  6656.  
  6657.                Copyright c 1991 IEEE.  All rights reserved.
  6658.       This is an unapproved IEEE Standards Draft, subject to change.
  6659.  
  6660.  
  6661.  
  6662.  
  6663.  
  6664.  2.5 Locale                                                             71
  6665.  
  6666.  
  6667.  
  6668.  
  6669.  
  6670.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6671.  
  6672.  Locales can be described with the file format presented in this
  6673.  subclause.  The file format is that accepted by the localedef utility
  6674.  (see 4.35).  For the purposes of this subclause, the file is referred to
  6675.  as the _l_o_c_a_l_e _d_e_f_i_n_i_t_i_o_n _f_i_l_e, but no locales shall be affected by this
  6676.  file unless it is processed by localedef or some similar mechanism.  Any   1
  6677.  requirements in this subclause imposed upon ``the utility'' shall apply    1
  6678.  to localedef or to any other similar utility used to install locale        1
  6679.  information using the locale definition file format described here.        1
  6680.  
  6681.  The locale definition file shall contain one or more locale category
  6682.  source definitions, and shall not contain more than one definition for
  6683.  the same locale category.  If the file contains source definitions for
  6684.  more than one category, implementation-defined categories, if present,
  6685.  shall appear after the categories defined by this clause (2.5).  A
  6686.  category source definition shall contain either the definition of a
  6687.  category or a copy directive.  For a description of the copy directive,
  6688.  see 4.35.  In the event that some of the information for a locale
  6689.  category, as specified in this standard, is missing from the locale
  6690.  source definition, the behavior of that category, if it is referenced, is
  6691.  unspecified.
  6692.  
  6693.  A category source definition shall consist of a category header, a
  6694.  category body, and a category trailer.  A category header shall consist
  6695.  of the character string naming of the category, beginning with the
  6696.  characters LC_.  The category trailer shall consist of the string END,     1
  6697.  followed by one or more <blank>s and the string used in the corresponding  1
  6698.  category header.
  6699.  
  6700.  The category body shall consist of one or more lines of text.  Each line
  6701.  shall contain an identifier, optionally followed by one or more operands.
  6702.  Identifiers shall be either keywords, identifying a particular locale
  6703.  element, or collating elements.  In addition to the keywords defined in
  6704.  this standard, the source can contain implementation-defined keywords.
  6705.  Each keyword within a locale shall have a unique name (i.e., two
  6706.  categories cannot have a commonly-named keyword); no keyword shall start
  6707.  with the characters LC_.  Identifiers shall be separated from the
  6708.  operands by one or more <blank>s.
  6709.  
  6710.  Operands shall be characters, collating elements, or strings of
  6711.  characters.  Strings shall be enclosed in double-quotes.  Literal          1
  6712.  double-quotes within strings shall be preceded by the <_e_s_c_a_p_e _c_h_a_r_a_c_t_e_r>,  1
  6713.  described below.  When a keyword is followed by more than one operand,     1
  6714.  the operands shall be separated by semicolons; <blank>s shall be allowed
  6715.  before and/or after a semicolon.
  6716.  
  6717.  The first category header in the file can be preceded by a line modifying
  6718.  the comment character.  It shall have the following format, starting in
  6719.  column 1:
  6720.  
  6721.  
  6722.  
  6723.                Copyright c 1991 IEEE.  All rights reserved.
  6724.       This is an unapproved IEEE Standards Draft, subject to change.
  6725.  
  6726.  
  6727.  
  6728.  
  6729.  
  6730.  72                                 2 Terminology and General Requirements
  6731.  
  6732.  
  6733.  
  6734.  
  6735.  
  6736.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6737.  
  6738.        "comment_char %c\n", <_c_o_m_m_e_n_t _c_h_a_r_a_c_t_e_r>
  6739.  
  6740.  The comment character shall default to the number-sign (#).  Blank lines
  6741.  and lines containing the <_c_o_m_m_e_n_t _c_h_a_r> in the first position shall be
  6742.  ignored.
  6743.  
  6744.  The first category header in the file can be preceded by a line modifying
  6745.  the escape character to be used in the file.  It shall have the following
  6746.  format, starting in column 1:
  6747.  
  6748.        "escape_char %c\n", <_e_s_c_a_p_e _c_h_a_r_a_c_t_e_r>
  6749.  
  6750.  The escape character shall default to backslash, which is the character
  6751.  used in all examples shown in this standard.
  6752.  
  6753.  A line can be continued by placing an escape character as the last
  6754.  character on the line; this continuation character shall be discarded      1
  6755.  from the input.  Although the implementation need not accept any one       1
  6756.  portion of a continued line with a length exceeding {LINE_MAX} bytes, it   1
  6757.  shall place no limits on the accumulated length of the continued line.     1
  6758.  Comment lines shall not be continued on a subsequent line using an         1
  6759.  escaped <newline>.
  6760.  
  6761.  Individual characters, characters in strings, and collating elements       2
  6762.  shall be represented using symbolic names, as defined below.  In           2
  6763.  addition, characters can be represented using the characters themselves,   2
  6764.  or as octal, hexadecimal, or decimal constants.  When nonsymbolic          2
  6765.  notation is used, the resultant locale definitions need not be portable    2
  6766.  between systems.  The left angle bracket (<) is a reserved symbol,         2
  6767.  denoting the start of a symbolic name; when used to represent itself it    2
  6768.  shall be preceded by the escape character.  The following rules apply to   2
  6769.  character representation:                                                  2
  6770.  
  6771.      (1)  A character can be represented via a symbolic name, enclosed      2
  6772.           within angle brackets (< and >).  The symbolic name, including    2
  6773.           the angle brackets, shall exactly match a symbolic name defined   2
  6774.           in the charmap file specified via the localedef -f option, and    2
  6775.           shall be replaced by a character value determined from the value  2
  6776.           associated with the symbolic name in the charmap file.  The use   2
  6777.           of a symbolic name not found in the _c_h_a_r_m_a_p file shall            1
  6778.           constitute an error, unless the category is LC_CTYPE or
  6779.           LC_COLLATE, in which case it shall constitute a warning
  6780.           condition (see localedef in 4.35 for a description of action
  6781.           resulting from errors and warnings).  The specification of a
  6782.           symbolic name in a collating-element or collating-symbol clause
  6783.           that duplicates a symbolic name in the charmap file (if present)
  6784.           is an error.  Use of the escape character or a right angle
  6785.           bracket within a symbolic name shall be invalid unless the
  6786.           character is preceded by the escape character.
  6787.  
  6788.  
  6789.                Copyright c 1991 IEEE.  All rights reserved.
  6790.       This is an unapproved IEEE Standards Draft, subject to change.
  6791.  
  6792.  
  6793.  
  6794.  
  6795.  
  6796.  2.5 Locale                                                             73
  6797.  
  6798.  
  6799.  
  6800.  
  6801.  
  6802.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6803.  
  6804.           _E_x_a_m_p_l_e:  <c>;<c-cedilla>  "<M><a><y>"
  6805.  
  6806.      (2)  A character can be represented by the character itself, in which  2
  6807.           case the value of the character is implementation defined.        2
  6808.           Within a string, the double-quote character, the escape           2
  6809.           character, and the right angle bracket character shall be         2
  6810.           escaped (preceded by the escape character) to be interpreted as   2
  6811.           the character itself.  Outside strings, the characters            2
  6812.  
  6813.                 ,     ;     <     >     _e_s_c_a_p_e__c_h_a_r                         2
  6814.  
  6815.           shall be escaped to be interpreted as the character itself.       2
  6816.  
  6817.           _E_x_a_m_p_l_e:  c    B   "May"
  6818.  
  6819.      (3)  A character can be represented as an octal constant.  An octal    2
  6820.           constant shall be specified as the escape character followed by   1
  6821.           two or more octal digits.  Each constant shall represent a byte   1
  6822.           value.  Multibyte characters can be represented by concatenated
  6823.           constants.
  6824.  
  6825.           _E_x_a_m_p_l_e:  \143;\347;\143\150   "\115\141\171"
  6826.  
  6827.      (4)  A character can be represented as a hexadecimal constant.  A      2
  6828.           hexadecimal constant shall be specified as the escape character   2
  6829.           followed by an x followed by two or more hexadecimal digits.      1
  6830.           Each constant shall represent a byte value.  Multibyte
  6831.           characters can be represented by concatenated constants.
  6832.  
  6833.           _E_x_a_m_p_l_e:  \x63;\xe7;\x63\x68   "\x4d\x61\x79"
  6834.  
  6835.      (5)  A character can be represented as a decimal constant.  A decimal  2
  6836.           constant shall be specified as the escape character followed by   2
  6837.           a d followed by two or more decimal digits.  Each constant shall  1
  6838.           represent a byte value.  Multibyte values can be represented by
  6839.           concatenated constants.
  6840.  
  6841.           _E_x_a_m_p_l_e:  \d99;\d231;\d99\d104  "\d77\d97\d121"
  6842.  
  6843.  Implementations may accept single-digit octal, decimal, or hexadecimal     1
  6844.  constants following the escape character.  Only characters existing in     1
  6845.  the character set for which the locale definition is created shall be      1
  6846.  specified, whether using symbolic names, the characters themselves, or     1
  6847.  octal, decimal, or hexadecimal constants.  If a charmap file is present,   2
  6848.  only characters defined in the charmap can be specified using octal,       2
  6849.  decimal, or hexadecimal constants.  Symbolic names not present in the      2
  6850.  charmap file can be specified and shall be ignored, as specified under     2
  6851.  item (1) above.                                                            2
  6852.  
  6853.  
  6854.  
  6855.                Copyright c 1991 IEEE.  All rights reserved.
  6856.       This is an unapproved IEEE Standards Draft, subject to change.
  6857.  
  6858.  
  6859.  
  6860.  
  6861.  
  6862.  74                                 2 Terminology and General Requirements
  6863.  
  6864.  
  6865.  
  6866.  
  6867.  
  6868.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  6869.  
  6870.  BEGIN_RATIONALE                                                            2
  6871.  
  6872.  2.5.2.0.1  Locale Definition Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  6873.             _P_1_0_0_3._2)
  6874.  
  6875.  The decision to separate the file format from the localedef utility        1
  6876.  description was only partially editorial.  Implementations may provide     1
  6877.  other interfaces than localedef.  Requirements on ``the utility,'' mostly  1
  6878.  concerning error messages, are described in this way because they are      1
  6879.  meant to affect the other interfaces implementations may provide as well   1
  6880.  as localedef.  (This is similar to the philosophy used by POSIX.1 {8}      1
  6881.  where the descriptions of the tar and cpio file formats impose             1
  6882.  requirements on any utilities processing them.)                            1
  6883.  
  6884.  The text about {POSIX2_LOCALEDEF} does not mean that internationalization
  6885.  is optional; only that the functionality of the localedef utility is.
  6886.  Regular expressions, for instance, must still be able to recognize e.g.,
  6887.  character class expressions such as [[:alpha:]].
  6888.  
  6889.  A possible analogy is with an applications development environment:
  6890.  while all conforming implementations must be capable of executing
  6891.  applications, not all need to have the development environment installed.
  6892.  The assumption is that the capability to modify the behavior of utilities
  6893.  (and applications) via locale settings must be supported.  If the
  6894.  localedef utility is not present, then the only choice is to select an
  6895.  existing (presumably implementation-documented) locale.  An
  6896.  implementation could, for example, chose to support only the POSIX
  6897.  Locale, which would in effect limit the amount of changes from historical
  6898.  implementations quite drastically.  The localedef utility is still
  6899.  required, but would always terminate with an exit code indicating that no
  6900.  locale could be created.  Supported locales must be documented using the
  6901.  syntax defined in 2.5.  (This ensures that users can accurately determine
  6902.  what capabilities are provided.  If the implementation decides to provide
  6903.  additional capabilities to the ones in 2.5, that is already provided
  6904.  for.)
  6905.  
  6906.  If the option is present (i.e., locales can be created), then the
  6907.  localedef utility must be capable of creating locales based on the syntax
  6908.  and rules defined in 2.5.  This does not mean that the implementation
  6909.  cannot also provide alternate means for creating locales.
  6910.  
  6911.  The octal, decimal, and hexadecimal notations are the same employed by     1
  6912.  the charmap facility (see 2.4.1).  To avoid confusion between an octal     1
  6913.  constant and a backreference, the octal, hexadecimal, and decimal          1
  6914.  constants must contain at least two digits.  As single-digit constants     1
  6915.  are relatively rare, this should not impose any significant hardship.      1
  6916.  Each of the constants includes ``two or more'' digits to account for       1
  6917.  systems in which the byte size is larger than eight bits.  For example, a  1
  6918.  Unicode system that has defined 16-bit bytes may require six octal, four   1
  6919.  
  6920.  
  6921.                Copyright c 1991 IEEE.  All rights reserved.
  6922.       This is an unapproved IEEE Standards Draft, subject to change.
  6923.  
  6924.  
  6925.  
  6926.  
  6927.  
  6928.  2.5 Locale                                                             75
  6929.  
  6930.  
  6931.  
  6932.  
  6933.  
  6934.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  6935.  
  6936.  hexadecimal, and five decimal digits.                                      1
  6937.  
  6938.  This standard is intended as an international (ISO/IEC) standard as well   1
  6939.  as an IEEE standard, and must therefore follow the ISO/IEC guidelines.     1
  6940.  One such rule is that characters outside the invariant part of             1
  6941.  ISO/IEC 646 {1} should not be used in portable specifications.  The        1
  6942.  backslash character is not in the invariant part; the number-sign is, but  1
  6943.  with multiple representations:  as a number-sign and as a pound sign.  As  1
  6944.  far as general usage of these symbols, they are covered by the             1
  6945.  ``grandfather clause,'' but for newly defined interfaces, ISO has          1
  6946.  requested that POSIX provides alternate representations.  Consequently,    1
  6947.  while the default escape character remains the backslash, and the default  1
  6948.  comment character is the number-sign, implementations are required to      1
  6949.  recognize alternative representations, identified in the applicable        1
  6950.  source file via the escape_char and comment_char keywords.                 1
  6951.  
  6952.  END_RATIONALE                                                              1
  6953.  
  6954.  
  6955.  2.5.2.1  LC_CTYPE
  6956.  
  6957.       Table 2-5  -  LC_CTYPE Category Definition in the POSIX Locale
  6958.  __________________________________________________________________________________________________________________________________________________
  6959.  LC_CTYPE
  6960.  # The following is the POSIX Locale LC_CTYPE.
  6961.  # "alpha" is by default "upper" and "lower"
  6962.  # "alnum" is by definition "alpha" and "digit"
  6963.  # "print" is by default "alnum", "punct" and the <space> character
  6964.  # "graph" is by default "alnum" and "punct"
  6965.  
  6966.  #
  6967.  upper    <A>;<B>;<C>;<D>;<E>;<F>;<G>;<H>;<I>;<J>;<K>;<L>;<M>;\
  6968.           <N>;<O>;<P>;<Q>;<R>;<S>;<T>;<U>;<V>;<W>;<X>;<Y>;<Z>
  6969.  #
  6970.  lower    <a>;<b>;<c>;<d>;<e>;<f>;<g>;<h>;<i>;<j>;<k>;<l>;<m>;\
  6971.           <n>;<o>;<p>;<q>;<r>;<s>;<t>;<u>;<v>;<w>;<x>;<y>;<z>
  6972.  #
  6973.  digit    <zero>;<one>;<two>;<three>;<four>;<five>;<six>;<seven>;<eight>;<nine>
  6974.  #
  6975.  space    <tab>;<newline>;<vertical-tab>;<form-feed>;<carriage-return>;<space>
  6976.  #
  6977.  cntrl    <alert>;<backspace>;<tab>;<newline>;<vertical-tab>;\
  6978.           <form-feed>;<carriage-return>;\
  6979.           <NUL>;<SOH>;<STX>;<ETX>;<EOT>;<ENQ>;<ACK>;<SO>;\
  6980.           <SI>;<DLE>;<DC1>;<DC2>;<DC3>;<DC4>;<NAK>;<SYN>;\
  6981.           <ETB>;<CAN>;<EM>;<SUB>;<ESC>;<IS4>;<IS3>;<IS2>;\
  6982.           <IS1>;<DEL>
  6983.  #
  6984.  punct    <exclamation-mark>;<quotation-mark>;<number-sign>;\
  6985.           <dollar-sign>;<percent-sign>;<ampersand>;<apostrophe>;\
  6986.  
  6987.                Copyright c 1991 IEEE.  All rights reserved.
  6988.       This is an unapproved IEEE Standards Draft, subject to change.
  6989.  
  6990.  
  6991.  
  6992.  
  6993.  
  6994.  76                                 2 Terminology and General Requirements
  6995.  
  6996.  
  6997.  
  6998.  
  6999.  
  7000.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7001.  
  7002.           <left-parenthesis>;<right-parenthesis>;<asterisk>;\
  7003.           <plus-sign>;<comma>;<hyphen>;<period>;<slash>;\
  7004.           <colon>;<semicolon>;<less-than-sign>;<equals-sign>;\
  7005.           <greater-than-sign>;<question-mark>;<commercial-at>
  7006.           <left-square-bracket>;<backslash>;<right-square-bracket>;\
  7007.           <circumflex>;<underline>;<grave-accent>;\
  7008.           <left-curly-bracket>;<vertical-line>;<right-curly-bracket>;<tilde>
  7009.  #
  7010.  xdigit   <zero>;<one>;<two>;<three>;<four>;<five>;<six>;<seven>;<eight>;\
  7011.           <nine>;<A>;<B>;<C>;<D>;<E>;<F>;<a>;<b>;<c>;<d>;<e>;<f>
  7012.  #
  7013.  blank    <space>;<tab>
  7014.  #
  7015.  toupper  (<a>,<A>);(<b>,<B>);(<c>,<C>);(<d>,<D>);(<e>,<E>);\
  7016.           (<f>,<F>);(<g>,<G>);(<h>,<H>);(<i>,<I>);(<j>,<J>);\
  7017.           (<k>,<K>);(<l>,<L>);(<m>,<M>);(<n>,<N>);(<o>,<O>);\
  7018.           (<p>,<P>);(<q>,<Q>);(<r>,<R>);(<s>,<S>);(<t>,<T>);\
  7019.           (<u>,<U>);(<v>,<V>);(<w>,<W>);(<x>,<X>);(<y>,<Y>);(<z>,<Z>)
  7020.  #
  7021.  tolower  (<A>,<a>);(<B>,<b>);(<C>,<c>);(<D>,<d>);(<E>,<e>);\
  7022.           (<F>,<f>);(<G>,<g>);(<H>,<h>);(<I>,<i>);(<J>,<j>);\
  7023.           (<K>,<k>);(<L>,<l>);(<M>,<m>);(<N>,<n>);(<O>,<o>);\
  7024.           (<P>,<p>);(<Q>,<q>);(<R>,<r>);(<S>,<s>);(<T>,<t>);\
  7025.           (<U>,<u>);(<V>,<v>);(<W>,<w>);(<X>,<x>);(<Y>,<y>);(<Z>,<z>)
  7026.  END LC_CTYPE
  7027.  __________________________________________________________________________________________________________________________________________________
  7028.  
  7029.  The LC_CTYPE category shall define character classification, case
  7030.  conversion, and other character attributes.  In addition, a series of
  7031.  characters can be represented by three adjacent periods representing an    1
  7032.  ellipsis symbol (``...'').  The ellipsis specification shall be            1
  7033.  interpreted as meaning that all values between the values preceding and    1
  7034.  following it represent valid characters.  The ellipsis specification only  1
  7035.  shall be valid within a single encoded character set.  An ellipsis shall
  7036.  be interpreted as including in the list all characters with an encoded
  7037.  value higher than the encoded value of the character preceding the
  7038.  ellipsis and lower than the encoded value of the character following the
  7039.  ellipsis.
  7040.  
  7041.  _E_x_a_m_p_l_e:  \x30;...;\x39; includes in the character class all characters
  7042.  with encoded values between the endpoints.
  7043.  
  7044.  The following keywords shall be recognized.  In the descriptions, the
  7045.  term ``automatically included'' means that it shall not be an error to
  7046.  either include the referenced characters or to omit them; the
  7047.  implementation shall provide them if missing and accept them silently if
  7048.  present.
  7049.  
  7050.  
  7051.  
  7052.  
  7053.                Copyright c 1991 IEEE.  All rights reserved.
  7054.       This is an unapproved IEEE Standards Draft, subject to change.
  7055.  
  7056.  
  7057.  
  7058.  
  7059.  
  7060.  2.5 Locale                                                             77
  7061.  
  7062.  
  7063.  
  7064.  
  7065.  
  7066.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7067.  
  7068.     copy         Specify the name of an existing locale to be used as the
  7069.                  source for the definition of this category.  If this
  7070.                  keyword is specified, no other keyword shall be
  7071.                  specified.
  7072.  
  7073.     upper        Define characters to be classified as uppercase letters.
  7074.                  No character specified for the keywords cntrl, digit,
  7075.                  punct, or space shall be specified.  If this keyword is    2
  7076.                  not specified, the uppercase letters A through Z, as       2
  7077.                  defined in Table 2-3 (see 2.4.1), shall automatically      2
  7078.                  belong to this class, with implementation-defined          2
  7079.                  character values.                                          2
  7080.  
  7081.     lower        Define characters to be classified as lowercase letters.
  7082.                  No character specified for the keywords cntrl, digit,
  7083.                  punct, or space shall be specified.  If this keyword is    2
  7084.                  not specified, the lowercase letters a through z, as       2
  7085.                  defined in Table 2-3 (see 2.4.1), shall automatically      2
  7086.                  belong to this class, with implementation-defined          2
  7087.                  character values.                                          2
  7088.  
  7089.     alpha        Define characters to be classified as letters.  No
  7090.                  character specified for the keywords cntrl, digit, punct,
  7091.                  or space shall be specified.  In addition, characters
  7092.                  classified as either upper or lower shall automatically
  7093.                  belong to this class.
  7094.  
  7095.     digit        Define the characters to be classified as numeric digits.  2
  7096.                  Only the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 shall be  2
  7097.                  specified, and in ascending sequence by numerical value.   2
  7098.                  If this keyword is not specified, the digits 0 through 9,  2
  7099.                  as defined in Table 2-3 (see 2.4.1), shall automatically   2
  7100.                  belong to this class, with implementation-defined          2
  7101.                  character values.                                          2
  7102.  
  7103.     space        Define characters to be classified as white-space
  7104.                  characters.  No character specified for the keywords
  7105.                  upper, lower, alpha, digit, graph, or xdigit shall be      1
  7106.                  specified.  If this keyword is not specified, the          2
  7107.                  characters <space>, <form-feed>, <newline>, <carriage-     2
  7108.                  return>, <tab>, and <vertical-tab>, as defined in          2
  7109.                  Table 2-3 (see 2.4.1), shall automatically belong to this  2
  7110.                  class, with implementation-defined character values.  Any  2
  7111.                  characters included in the class blank shall be            1
  7112.                  automatically included.                                    1
  7113.  
  7114.     cntrl        Define characters to be classified as control characters.
  7115.                  No character specified for the keywords upper, lower,
  7116.                  alpha, digit, punct, graph, print, or xdigit shall be      1
  7117.  
  7118.  
  7119.                Copyright c 1991 IEEE.  All rights reserved.
  7120.       This is an unapproved IEEE Standards Draft, subject to change.
  7121.  
  7122.  
  7123.  
  7124.  
  7125.  
  7126.  78                                 2 Terminology and General Requirements
  7127.  
  7128.  
  7129.  
  7130.  
  7131.  
  7132.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7133.  
  7134.                  specified.                                                 1
  7135.  
  7136.     punct        Define characters to be classified as punctuation
  7137.                  characters.  No character specified for the keywords
  7138.                  upper, lower, alpha, digit, cntrl, xdigit, or as the
  7139.                  <space> character shall be specified.
  7140.  
  7141.     graph        Define characters to be classified as printable
  7142.                  characters, not including the <space> character.  If this
  7143.                  keyword is not specified, characters specified for the
  7144.                  keywords upper, lower, alpha, digit, xdigit, and punct
  7145.                  shall belong to this character class.  No character
  7146.                  specified for the keyword cntrl shall be specified.
  7147.  
  7148.     print        Define characters to be classified as printable
  7149.                  characters, including the <space> character.  If this
  7150.                  keyword is not provided, characters specified for the
  7151.                  keywords upper, lower, alpha, digit, xdigit, punct, and
  7152.                  the <space> character shall belong to this character
  7153.                  class.  No character specified for the keyword cntrl
  7154.                  shall be specified.
  7155.  
  7156.     xdigit       Define the characters to be classified as hexadecimal
  7157.                  digits.  Only the characters defined for the class digit   2
  7158.                  shall be specified, in ascending sequence by numerical     2
  7159.                  value, followed by one or more sets of six characters      2
  7160.                  representing the hexadecimal digits 10 through 15, with    2
  7161.                  each set in ascending order (for example A, B, C, D, E,    2
  7162.                  F, a, b, c, d, e, f).  If this keyword is not specified,   2
  7163.                  the digits 0 through 9, the uppercase letters A through    2
  7164.                  F, and the lowercase letters a through f, as defined in    2
  7165.                  Table 2-3 (see 2.4.1), shall automatically belong to this  2
  7166.                  class, with implementation-defined character values.       2
  7167.  
  7168.     blank        Define characters to be classified as <blank> characters.
  7169.                  If this keyword is unspecified, the characters <space>
  7170.                  and <tab> shall belong to this character class.
  7171.  
  7172.     toupper      Define the mapping of lowercase letters to uppercase
  7173.                  letters.  The operand shall consist of character pairs,
  7174.                  separated by semicolons.  The characters in each
  7175.                  character pair shall be separated by a comma and the pair
  7176.                  enclosed by parentheses.  The first character in each
  7177.                  pair shall be the lowercase letter, the second the
  7178.                  corresponding uppercase letter.  Only characters
  7179.                  specified for the keywords lower and upper shall be
  7180.                  specified.  If this keyword is not specified, the          2
  7181.                  lowercase letters a through z, and their corresponding     2
  7182.                  uppercase letters A through Z, as defined in Table 2-3     2
  7183.  
  7184.  
  7185.                Copyright c 1991 IEEE.  All rights reserved.
  7186.       This is an unapproved IEEE Standards Draft, subject to change.
  7187.  
  7188.  
  7189.  
  7190.  
  7191.  
  7192.  2.5 Locale                                                             79
  7193.  
  7194.  
  7195.  
  7196.  
  7197.  
  7198.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7199.  
  7200.                  (see 2.4.1), shall automatically be included, with         2
  7201.                  implementation-defined character values.                   2
  7202.  
  7203.     tolower      Define the mapping of uppercase letters to lowercase
  7204.                  letters.  The operand shall consist of character pairs,
  7205.                  separated by semicolons.  The characters in each
  7206.                  character pair are separated by a comma and the pair
  7207.                  enclosed by parentheses.  The first character in each
  7208.                  pair shall be the uppercase letter, the second the
  7209.                  corresponding lowercase letter.  Only characters
  7210.                  specified for the keywords lower and upper shall be
  7211.                  specified.
  7212.  
  7213.                  The tolower keyword is optional.  If specified, the
  7214.                  uppercase letters A through Z, as defined in Table 2-3,
  7215.                  and their corresponding lowercase letter, shall be
  7216.                  specified.  If this keyword is not specified, the mapping
  7217.                  shall be the reverse mapping of the one specified for
  7218.                  toupper.
  7219.  
  7220.  Table 2-6 shows the allowed character class combinations.
  7221.  
  7222.  
  7223.  
  7224.  
  7225.  
  7226.  
  7227.  
  7228.  
  7229.  
  7230.  
  7231.  
  7232.  
  7233.  
  7234.  
  7235.  
  7236.  
  7237.  
  7238.  
  7239.  
  7240.  
  7241.  
  7242.  
  7243.  
  7244.  
  7245.  
  7246.  
  7247.  
  7248.  
  7249.  
  7250.  
  7251.                Copyright c 1991 IEEE.  All rights reserved.
  7252.       This is an unapproved IEEE Standards Draft, subject to change.
  7253.  
  7254.  
  7255.  
  7256.  
  7257.  
  7258.  80                                 2 Terminology and General Requirements
  7259.  
  7260.  
  7261.  
  7262.  
  7263.  
  7264.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7265.  
  7266.  
  7267.              Table 2-6  -  Valid Character Class Combinations
  7268.  __________________________________________________________________________________________________________________________________________________
  7269.  _____________________________________________________________________________
  7270.  |  In   |_________________________C_a_n__A_l_s_o__B_e_l_o_n_g__T_o__________________________|
  7271.  |Class  | upper lower alpha digit space cntrl punct graph print xdigit blank |
  7272.  _|________|____________________________________________________________________|
  7273.  |upper  |   -     -     M     X     X     X     X     D     D     -      X   |
  7274.  |lower  |   -     -     M     X     X     X     X     D     D     -      X   |
  7275.  |alpha  |   -     -     -     X     X     X     X     D     D     -      X   |
  7276.  |digit  |   X     X     X     -     X     X     X     D     D     -      X   |
  7277.  |space  |   X     X     X     X     -     -     *     *     *     X      -  2|
  7278.  |cntrl  |   X     X     X     X     -     -     X     X     X     X      -  2|
  7279.  |punct  |   X     X     X     X     -     X     -     D     D     X      -   |
  7280.  |graph  |   -     -     -     -     -     X     -     -     -     -      -   |
  7281.  |print  |   -     -     -     -     -     X     -     -     -     -      -   |
  7282.  |xdigit |   -     -     -     -     X     X     X     D     D     -      X   |
  7283.  _||b_l_a_n_k____||___X______X______X______X______M______-______*______*______*______X_______-___2_||
  7284.  
  7285.  NOTES:
  7286.  
  7287.      (1)  Explanation of codes:
  7288.  
  7289.              M     Always
  7290.  
  7291.              D     Default; belongs to class if not specified
  7292.  
  7293.              -     Permitted
  7294.  
  7295.              X     Mutually exclusive
  7296.  
  7297.              *     See note (2)
  7298.  
  7299.      (2)  The <space> character, which is part of the space and blank
  7300.           classes, cannot belong to punct or graph, but automatically
  7301.           shall belong to the print class.  Other space or blank
  7302.           characters can be classified as punct, graph, and/or print.
  7303.  
  7304.  __________________________________________________________________________________________________________________________________________________
  7305.  
  7306.  
  7307.  BEGIN_RATIONALE
  7308.  
  7309.  2.5.2.1.1  LC_CTYPE Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  7310.  
  7311.  The LC_CTYPE category primarily is used to define the encoding-
  7312.  independent aspects of a character set, such as character classification.
  7313.  In addition, certain encoding-dependent characteristics are also defined
  7314.  for an application via the LC_CTYPE category.  POSIX.2 does not mandate
  7315.  
  7316.  
  7317.                Copyright c 1991 IEEE.  All rights reserved.
  7318.       This is an unapproved IEEE Standards Draft, subject to change.
  7319.  
  7320.  
  7321.  
  7322.  
  7323.  
  7324.  2.5 Locale                                                             81
  7325.  
  7326.  
  7327.  
  7328.  
  7329.  
  7330.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7331.  
  7332.  that the encoding used in the locale is the same as the one used by the
  7333.  application, because an implementation may decide that it is advantageous
  7334.  to define locales in a system-wide encoding rather than having multiple,
  7335.  logically identical locales in different encodings, and to convert from
  7336.  the application encoding to the system-wide encoding on usage.  Other
  7337.  implementations could require encoding-dependent locales.
  7338.  
  7339.  In either case, the LC_CTYPE attributes that are directly dependent on
  7340.  the encoding, such as mb_cur_max and the display width of characters, are
  7341.  not user-specifiable in a locale source, and are consequently not defined
  7342.  as keywords.
  7343.  
  7344.  As the LC_CTYPE character classes are based on the C Standard {7}
  7345.  character-class definition, the category does not support multicharacter
  7346.  elements.  For instance, the German character <sharp-s> is traditionally
  7347.  classified as a lowercase letter.  There is no corresponding uppercase
  7348.  letter; in proper capitalization of German text the <sharp-s> will be
  7349.  replaced by SS; i.e., by two characters.  This kind of conversion is
  7350.  outside the scope of the toupper and tolower keywords.
  7351.  
  7352.  Where POSIX.2 specifies that only certain characters can be specified, as  1
  7353.  for the keywords digit and xdigit, the specified characters must be from   1
  7354.  the portable character set, as shown.  As an example, only the Arabic      1
  7355.  digits 0 through 9 are acceptable as digits.                               1
  7356.  
  7357.  The character classes digit, xdigit, lower, upper, and space have a set    2
  7358.  of automatically included characters.  These only need to be specified if  2
  7359.  the character values (i.e., encoding) differs from the implementation      2
  7360.  default values.                                                            2
  7361.  
  7362.  The definition of character class digit requires that only ten             2
  7363.  characters--the ones defining digits--can be specified; alternate digits   2
  7364.  (e.g., Hindi or Kanji) cannot be specified here.  However, the encoding    2
  7365.  may vary if an implementation supports more than one encoding.             2
  7366.  
  7367.  The definition of character class xdigit requires that the characters      2
  7368.  included in character class digit are included here also, and allows for   2
  7369.  different symbols for the hexadecimal digits 10 through 15.                2
  7370.  
  7371.  END_RATIONALE                                                              2
  7372.  
  7373.  
  7374.  2.5.2.2  LC_COLLATE
  7375.  
  7376.  A collation sequence definition shall define the relative order between
  7377.  collating elements (characters and multicharacter collating elements) in
  7378.  the locale.  This order is expressed in terms of collation values; i.e.,
  7379.  by assigning each element one or more collation values (also known as
  7380.  collation weights).  This does not imply that implementations shall
  7381.  assign such values, but that ordering of strings using the resultant
  7382.  
  7383.                Copyright c 1991 IEEE.  All rights reserved.
  7384.       This is an unapproved IEEE Standards Draft, subject to change.
  7385.  
  7386.  
  7387.  
  7388.  
  7389.  
  7390.  82                                 2 Terminology and General Requirements
  7391.  
  7392.  
  7393.  
  7394.  
  7395.  
  7396.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7397.  
  7398.  collation definition in the locale shall behave as if such assignment is
  7399.  done and used in the collation process.  The collation sequence
  7400.  definition shall be used by regular expressions, pattern matching, and
  7401.  sorting.  The following capabilities are provided:
  7402.  
  7403.      (1)  Multicharacter collating elements.  Specification of
  7404.           multicharacter collating elements (i.e., sequences of two or
  7405.           more characters to be collated as an entity).
  7406.  
  7407.      (2)  User-defined ordering of collating elements.  Each collating
  7408.           element shall be assigned a collation value defining its order
  7409.           in the character (or basic) collation sequence.  This ordering
  7410.           is used by regular expressions and pattern matching and, unless
  7411.           collation weights are explicitly specified, also as the
  7412.           collation weight to be used in sorting.
  7413.  
  7414.      (3)  Multiple weights and equivalence classes.  Collating elements
  7415.           can be assigned one or more (up to the limit {COLL_WEIGHTS_MAX})
  7416.           collating weights for use in sorting.  The first weight is
  7417.           hereafter referred to as the primary weight.
  7418.  
  7419.      (4)  One-to-Many mapping.  A single character is mapped into a string
  7420.           of collating elements.
  7421.  
  7422.      (5)  Many-to-Many substitution.  A string of one or more characters
  7423.           is substituted by another string (or an empty string, i.e., the
  7424.           character or characters shall be ignored for collation
  7425.           purposes).
  7426.  
  7427.      (6)  Equivalence class definition.  Two or more collating elements
  7428.           have the same collation value (primary weight).
  7429.  
  7430.      (7)  Ordering by weights.  When two strings are compared to determine  2
  7431.           their relative order, the two strings are first broken up into a  2
  7432.           series of collating elements, and each successive pair of         2
  7433.           elements are compared according to the relative primary weights   2
  7434.           for the elements.  If equal, and more than one weight has been    2
  7435.           assigned, then the pairs of collating elements are recompared     2
  7436.           according to the relative subsequent weights, until either a      2
  7437.           pair of collating elements compare unequal or the weights are     2
  7438.           exhausted.                                                        2
  7439.  
  7440.  The following keywords shall be recognized in a collation sequence
  7441.  definition.  They are described in detail in the following subclauses.
  7442.  
  7443.     copy                  Specify the name of an existing locale to be
  7444.                           used as the source for the definition of this
  7445.                           category.  If this keyword is specified, no
  7446.                           other keyword shall be specified.
  7447.  
  7448.  
  7449.                Copyright c 1991 IEEE.  All rights reserved.
  7450.       This is an unapproved IEEE Standards Draft, subject to change.
  7451.  
  7452.  
  7453.  
  7454.  
  7455.  
  7456.  2.5 Locale                                                             83
  7457.  
  7458.  
  7459.  
  7460.  
  7461.  
  7462.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7463.  
  7464.     collating-element     Define a collating-element symbol representing a  1
  7465.                           multicharacter collating element.  This keyword   1
  7466.                           is optional.
  7467.  
  7468.     collating-symbol      Define a collating symbol for use in collation    1
  7469.                           order statements.  This keyword is optional.      1
  7470.  
  7471.                                                                             2
  7472.  
  7473.     order_start           Define collation rules.  This statement is
  7474.                           followed by one or more collation order
  7475.                           statements, assigning character collation values
  7476.                           and collation weights to collating elements.
  7477.  
  7478.     order_end             Specify the end of the collation-order            1
  7479.                           statements.                                       1
  7480.  
  7481.      Table 2-7  -  LC_COLLATE Category Definition in the POSIX Locale
  7482.  __________________________________________________________________________________________________________________________________________________
  7483.  LC_COLLATE
  7484.  # This is the POSIX Locale definition for the LC_COLLATE category.
  7485.  # The order is the same as in the ASCII code set.
  7486.  order_start forward
  7487.  <NUL>
  7488.  <SOH>
  7489.  <STX>
  7490.  <ETX>
  7491.  <EOT>
  7492.  <ENQ>
  7493.  <ACK>
  7494.  <alert>
  7495.  <backspace>
  7496.  <tab>
  7497.  <newline>
  7498.  <vertical-tab>
  7499.  <form-feed>
  7500.  <carriage-return>
  7501.  <SO>
  7502.  <SI>
  7503.  <DLE>
  7504.  <DC1>
  7505.  <DC2>
  7506.  <DC3>
  7507.  <DC4>
  7508.  <NAK>
  7509.  <SYN>
  7510.  <ETB>
  7511.  <CAN>
  7512.  <EM>
  7513.  
  7514.  
  7515.                Copyright c 1991 IEEE.  All rights reserved.
  7516.       This is an unapproved IEEE Standards Draft, subject to change.
  7517.  
  7518.  
  7519.  
  7520.  
  7521.  
  7522.  84                                 2 Terminology and General Requirements
  7523.  
  7524.  
  7525.  
  7526.  
  7527.  
  7528.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7529.  
  7530.  <SUB>
  7531.  <ESC>
  7532.  <IS4>
  7533.  <IS3>
  7534.  <IS2>
  7535.  <IS1>
  7536.  <space>
  7537.  <exclamation-mark>
  7538.  <quotation-mark>
  7539.  <number-sign>
  7540.  <dollar-sign>
  7541.  <percent-sign>
  7542.  <ampersand>
  7543.  <apostrophe>
  7544.  <left-parenthesis>
  7545.  <right-parenthesis>
  7546.  <asterisk>
  7547.  _________________________________________________________________________
  7548.  
  7549.  Table 2-7 - LC_COLLATE Category Definition in the POSIX Locale (_c_o_n_t_i_n_u_e_d)
  7550.  _________________________________________________________________________
  7551.  <plus-sign>
  7552.  <comma>
  7553.  <hyphen>
  7554.  <period>
  7555.  <slash>
  7556.  <zero>
  7557.  <one>
  7558.  <two>
  7559.  <three>
  7560.  <four>
  7561.  <five>
  7562.  <six>
  7563.  <seven>
  7564.  <eight>
  7565.  <nine>
  7566.  <colon>
  7567.  <semicolon>
  7568.  <less-than-sign>
  7569.  <equals-sign>
  7570.  <greater-than-sign>
  7571.  <question-mark>
  7572.  <commercial-at>
  7573.  <A>
  7574.  <B>
  7575.  <C>
  7576.  <D>
  7577.  <E>
  7578.  <F>
  7579.  
  7580.  
  7581.                Copyright c 1991 IEEE.  All rights reserved.
  7582.       This is an unapproved IEEE Standards Draft, subject to change.
  7583.  
  7584.  
  7585.  
  7586.  
  7587.  
  7588.  2.5 Locale                                                             85
  7589.  
  7590.  
  7591.  
  7592.  
  7593.  
  7594.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7595.  
  7596.  <G>
  7597.  <H>
  7598.  <I>
  7599.  <J>
  7600.  <K>
  7601.  <L>
  7602.  <M>
  7603.  <N>
  7604.  <O>
  7605.  <P>
  7606.  <Q>
  7607.  <R>
  7608.  <S>
  7609.  <T>
  7610.  <U>
  7611.  <V>
  7612.  <W>
  7613.  <X>
  7614.  <Y>
  7615.  <Z>
  7616.  _________________________________________________________________________
  7617.  
  7618.  2.5.2.2.1  collating-element Keyword
  7619.  
  7620.  In addition to the collating elements in the character set, the
  7621.  collating-element keyword shall be used to define multicharacter
  7622.  collating elements.  The syntax is
  7623.  
  7624.        "collating-element %s from %s\n", <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l>, <_s_t_r_i_n_g>
  7625.  
  7626.  The <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l> operand shall be a symbolic name, enclosed between  1
  7627.  angle brackets (< and >), and shall not duplicate any symbolic name in
  7628.  the current charmap file (if any), or any other symbolic name defined in
  7629.  this collation definition.  The string operand shall be a string of two
  7630.  or more characters that shall collate as an entity.  A <_c_o_l_l_a_t_i_n_g-         1
  7631.  _e_l_e_m_e_n_t> defined via this keyword is only recognized with the LC_COLLATE   1
  7632.  category.
  7633.  
  7634.  _E_x_a_m_p_l_e:
  7635.  
  7636.        collating-element <ch> from <c><h>
  7637.        collating-element <e-acute> from <acute><e>
  7638.        collating-element <ll> from ll
  7639.  
  7640.  
  7641.  
  7642.  
  7643.  
  7644.  
  7645.  
  7646.  
  7647.                Copyright c 1991 IEEE.  All rights reserved.
  7648.       This is an unapproved IEEE Standards Draft, subject to change.
  7649.  
  7650.  
  7651.  
  7652.  
  7653.  
  7654.  86                                 2 Terminology and General Requirements
  7655.  
  7656.  
  7657.  
  7658.  
  7659.  
  7660.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7661.  
  7662.  Table 2-7 - LC_COLLATE Category Definition in the POSIX Locale (_c_o_n_c_l_u_d_e_d)
  7663.  _________________________________________________________________________
  7664.  <left-square-bracket>
  7665.  <backslash>
  7666.  <right-square-bracket>
  7667.  <circumflex>
  7668.  <underline>
  7669.  <grave-accent>
  7670.  <a>
  7671.  <b>
  7672.  <c>
  7673.  <d>
  7674.  <e>
  7675.  <f>
  7676.  <g>
  7677.  <h>
  7678.  <i>
  7679.  <j>
  7680.  <k>
  7681.  <l>
  7682.  <m>
  7683.  <n>
  7684.  <o>
  7685.  <p>
  7686.  <q>
  7687.  <r>
  7688.  <s>
  7689.  <t>
  7690.  <u>
  7691.  <v>
  7692.  <w>
  7693.  <x>
  7694.  <y>
  7695.  <z>
  7696.  <left-curly-bracket>
  7697.  <vertical-line>
  7698.  <right-curly-bracket>
  7699.  <tilde>
  7700.  <DEL>
  7701.  order_end
  7702.  #
  7703.  END LC_COLLATE
  7704.  __________________________________________________________________________________________________________________________________________________
  7705.  
  7706.  _2._5._2._2._2  collating-symbol _K_e_y_w_o_r_d
  7707.  
  7708.  This keyword shall be used to define symbols for use in collation
  7709.  sequence statements; i.e., between the order_start and the order_end
  7710.  keywords.  The syntax is
  7711.  
  7712.  
  7713.                Copyright c 1991 IEEE.  All rights reserved.
  7714.       This is an unapproved IEEE Standards Draft, subject to change.
  7715.  
  7716.  
  7717.  
  7718.  
  7719.  
  7720.  2.5 Locale                                                             87
  7721.  
  7722.  
  7723.  
  7724.  
  7725.  
  7726.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7727.  
  7728.        "collating-symbol %s\n", <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l>
  7729.  
  7730.  The <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l> shall be a symbolic name, enclosed between angle    1
  7731.  brackets (< and >), and shall not duplicate any symbolic name in the
  7732.  current charmap file (if any), or any other symbolic name defined in this
  7733.  collation definition.  A <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l> defined via this keyword is
  7734.  only recognized with the LC_COLLATE category.
  7735.  
  7736.  _E_x_a_m_p_l_e:
  7737.  
  7738.        collating-symbol <UPPER_CASE>
  7739.        collating-symbol <HIGH>
  7740.  
  7741.                                                                             2
  7742.  
  7743.  _2._5._2._2._3  order_start _K_e_y_w_o_r_d
  7744.  
  7745.  The order_start keyword shall precede collation order entries and also
  7746.  defines the number of weights for this collation sequence definition and
  7747.  other collation rules.
  7748.  
  7749.  The syntax of the order_start keyword is:
  7750.  
  7751.        "order_start %s;%s;...;%s\n", <_s_o_r_t-_r_u_l_e_s>, <_s_o_r_t-_r_u_l_e_s> ...
  7752.  
  7753.  The operands to the order_start keyword are optional.  If present, the
  7754.  operands define rules to be applied when strings are compared.  The
  7755.  number of operands define how many weights each element is assigned; if
  7756.  no operands are present, one forward operand is assumed.  If present, the
  7757.  first operand defines rules to be applied when comparing strings using
  7758.  the first (primary) weight; the second when comparing strings using the
  7759.  second weight, and so on.  Operands shall be separated by semicolons (;).
  7760.  Each operand shall consist of one or more collation directives, separated
  7761.  by commas (,).  If the number or operands exceeds the {COLL_WEIGHTS_MAX}
  7762.  limit, the utility shall issue a warning message.  The following
  7763.  directives shall be supported:
  7764.  
  7765.     forward            Specifies that comparison operations for the weight
  7766.                        level shall proceed from start of string towards
  7767.                        the end of string.
  7768.  
  7769.     backward           Specifies that comparison operations for the weight
  7770.                        level shall proceed from end of string towards the
  7771.                        beginning of string.
  7772.  
  7773.                                                                             2
  7774.  
  7775.     position           Specifies that comparison operations for the weight
  7776.                        level will consider the relative position of non-    2
  7777.  
  7778.  
  7779.                Copyright c 1991 IEEE.  All rights reserved.
  7780.       This is an unapproved IEEE Standards Draft, subject to change.
  7781.  
  7782.  
  7783.  
  7784.  
  7785.  
  7786.  88                                 2 Terminology and General Requirements
  7787.  
  7788.  
  7789.  
  7790.  
  7791.  
  7792.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7793.  
  7794.                        IGNOREd elements in the strings.  The string         2
  7795.                        containing a non-IGNOREd element after the fewest    2
  7796.                        IGNOREd collating elements from the start of the     2
  7797.                        compare shall collate first.  If both strings        2
  7798.                        contain a non-IGNOREd character in the same          2
  7799.                        relative position, the collating values assigned to  2
  7800.                        the elements shall determine the ordering.  In case  2
  7801.                        of equality, subsequent non-IGNOREd characters       2
  7802.                        shall be considered in the same manner.              2
  7803.  
  7804.  The directives forward and backward are mutually exclusive.
  7805.  
  7806.  _E_x_a_m_p_l_e:
  7807.  
  7808.        order_start     forward;backward                                     2
  7809.  
  7810.  If no operands are specified, a single forward operand shall be assumed.   1
  7811.  
  7812.  2.5.2.2.4  Collation Order
  7813.  
  7814.  The order_start keyword shall be followed by collating element entries.
  7815.  The syntax for the collating element entries is
  7816.  
  7817.        "%s %s;%s;...;%s\n", <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t>, <_w_e_i_g_h_t>, <_w_e_i_g_h_t>, ...
  7818.  
  7819.  Each _c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t shall consist of either a character (in any of the  1
  7820.  forms defined in 2.5.2), a <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t>, a <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l>, an   1
  7821.  ellipsis, or the special symbol UNDEFINED.  The order in which collating   1
  7822.  elements are specified determines the character collation sequence, such   1
  7823.  that each collating element shall compare less than the elements           1
  7824.  following it.  The NUL character shall compare lower than any other        1
  7825.  character.                                                                 1
  7826.  
  7827.  A <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t> shall be used to specify multicharacter collating    1
  7828.  elements, and indicates that the character sequence specified via the      1
  7829.  <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t> is to be collated as a unit and in the relative order  1
  7830.  specified by its place.                                                    1
  7831.  
  7832.  A <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l> shall be used to define a position in the relative    1
  7833.  order for use in weights.                                                  1
  7834.  
  7835.  The ellipsis symbol (``...'') specifies that a sequence of characters      1
  7836.  shall collate according to their encoded character values.  It shall be    1
  7837.  interpreted as indicating that all characters with a coded character set
  7838.  value higher than the value of the character in the preceding line, and
  7839.  lower than the coded character set value for the character in the
  7840.  following line, in the current coded character set, shall be placed in
  7841.  the character collation order between the previous and the following
  7842.  character in ascending order according to their coded character set
  7843.  
  7844.  
  7845.                Copyright c 1991 IEEE.  All rights reserved.
  7846.       This is an unapproved IEEE Standards Draft, subject to change.
  7847.  
  7848.  
  7849.  
  7850.  
  7851.  
  7852.  2.5 Locale                                                             89
  7853.  
  7854.  
  7855.  
  7856.  
  7857.  
  7858.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7859.  
  7860.  values.  An initial ellipsis shall be interpreted as if the preceding
  7861.  line specified the NUL character, and a trailing ellipsis as if the
  7862.  following line specified the highest coded character set value in the
  7863.  current coded character set.  An ellipsis shall be treated as invalid if
  7864.  the preceding or following lines do not specify characters in the current
  7865.  coded character set.  The use of the ellipsis symbol ties the definition   1
  7866.  to a specific coded character set and may preclude the definition from     1
  7867.  being portable between implementations.                                    1
  7868.  
  7869.  The symbol UNDEFINED shall be interpreted as including all coded
  7870.  character set values not specified explicitly or via the ellipsis symbol.
  7871.  Such characters shall be inserted in the character collation order at the
  7872.  point indicated by the symbol, and in ascending order according to their   1
  7873.  coded character set values.  If no UNDEFINED symbol is specified, and the  1
  7874.  current coded character set contains characters not specified in this
  7875.  clause, the utility shall issue a warning message and place such
  7876.  characters at the end of the character collation order.
  7877.  
  7878.  The optional operands for each collation-element shall be used to define
  7879.  the primary, secondary, or subsequent weights for the collating element.
  7880.  The first operand specifies the relative primary weight, the second the
  7881.  relative secondary weight, and so on.  Two or more collation-elements can
  7882.  be assigned the same weight; they belong to the same _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s if  1
  7883.  they have the same primary weight.  Collation shall behave as if, for      1
  7884.  each weight level, IGNOREd elements are removed.  Then each successive     2
  7885.  pair of elements shall be compared according to the relative weights for   1
  7886.  the elements.  If the two strings compare equal, the process shall be      1
  7887.  repeated for the next weight level, up to the limit {COLL_WEIGHTS_MAX}.    1
  7888.  
  7889.  Weights shall be expressed as characters (in any of the forms specified    1
  7890.  in 2.5.2), <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l>s, <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t>s, an ellipsis, or the  1
  7891.  special symbol IGNORE.  A single character, a <_c_o_l_l_a_t_i_n_g-_s_y_m_b_o_l>, or a     1
  7892.  <_c_o_l_l_a_t_i_n_g-_e_l_e_m_e_n_t> shall represent the relative order in the character    1
  7893.  collating sequence of the character or symbol, rather than the character   1
  7894.  or characters themselves.                                                  1
  7895.  
  7896.  One-to-many mapping is indicated by specifying two or more concatenated    1
  7897.  characters or symbolic names.  Thus, if the character ``<eszet>'' is       1
  7898.  given the string <s><s> as a weight, comparisons shall be performed as if  1
  7899.  all occurrences of the character <eszet> are replaced by <s><s>.  If it    1
  7900.  is desirable to define <eszet> and <s><s> as an equivalence class, then a  1
  7901.  collating-element must be defined for the string ``ss'', as in the         1
  7902.  example below.                                                             1
  7903.  
  7904.  All characters specified via an ellipsis shall by default be assigned      1
  7905.  unique weights, equal to the relative order of characters.  Characters     1
  7906.  specified via an explicit or implicit UNDEFINED special symbol shall by    1
  7907.  default be assigned the same primary weight (i.e., belong to the same      1
  7908.  equivalence class).  An ellipsis symbol as a weight shall be interpreted   1
  7909.  
  7910.  
  7911.                Copyright c 1991 IEEE.  All rights reserved.
  7912.       This is an unapproved IEEE Standards Draft, subject to change.
  7913.  
  7914.  
  7915.  
  7916.  
  7917.  
  7918.  90                                 2 Terminology and General Requirements
  7919.  
  7920.  
  7921.  
  7922.  
  7923.  
  7924.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  7925.  
  7926.  to mean that each character in the sequence shall have unique weights,     1
  7927.  equal to the relative order of their character in the character collation  1
  7928.  sequence.  Secondary and subsequent weights have unique values.  The use   1
  7929.  of the ellipsis as a weight shall be treated as an error if the collating  1
  7930.  element is neither an ellipsis nor the special symbol UNDEFINED.           1
  7931.  
  7932.  The special keyword IGNORE as a weight shall indicate that when strings
  7933.  are compared using the weights at the level where IGNORE is specified,
  7934.  the collating element shall be ignored; i.e., as if the string did not
  7935.  contain the collating element.  In regular expressions and pattern
  7936.  matching, all characters that are IGNOREd in their primary weight form an
  7937.  equivalence class.
  7938.  
  7939.  An empty operand shall be interpreted as the collating-element itself.
  7940.  
  7941.  For example, the order statement
  7942.  
  7943.        <a>     <a>;<a>
  7944.  
  7945.  is equal to
  7946.  
  7947.        <a>
  7948.  
  7949.  An ellipsis can be used as an operand if the collating-element was an
  7950.  ellipsis, and shall be interpreted as the value of each character defined
  7951.  by the ellipsis.
  7952.  
  7953.  The collation order as defined in this clause defines the interpretation   1
  7954.  of bracket expressions in regular expressions (see 2.8.3.2).               1
  7955.  
  7956.  
  7957.  
  7958.  
  7959.  
  7960.  
  7961.  
  7962.  
  7963.  
  7964.  
  7965.  
  7966.  
  7967.  
  7968.  
  7969.  
  7970.  
  7971.  
  7972.  
  7973.  
  7974.  
  7975.  
  7976.  
  7977.                Copyright c 1991 IEEE.  All rights reserved.
  7978.       This is an unapproved IEEE Standards Draft, subject to change.
  7979.  
  7980.  
  7981.  
  7982.  
  7983.  
  7984.  2.5 Locale                                                             91
  7985.  
  7986.  
  7987.  
  7988.  
  7989.  
  7990.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  7991.  
  7992.        _E_x_a_m_p_l_e:
  7993.  
  7994.        order_start   forward;backward
  7995.        UNDEFINED     IGNORE;IGNORE
  7996.        <LOW>
  7997.        <space>       <LOW>;<space>
  7998.        ...           <LOW>;...
  7999.        <a>           <a>;<a>
  8000.        <a-acute>     <a>;<a-acute>
  8001.        <a-grave>     <a>;<a-grave>
  8002.        <A>           <a>;<A>
  8003.        <A-acute>     <a>;<A-acute>
  8004.        <A-grave>     <a>;<A-grave>
  8005.        <ch>          <ch>;<ch>
  8006.        <Ch>          <ch>;<Ch>
  8007.        <s>           <s>;<s>
  8008.                                                                             2
  8009.        <eszet>       <s><s>;<eszet><eszet>
  8010.        ...           <HIGH>;...
  8011.        <HIGH>
  8012.        order_end
  8013.  
  8014.  This example is interpreted as follows:
  8015.  
  8016.      (1)  The UNDEFINED means that all characters not specified in this
  8017.           definition (explicitly or via the ellipsis) shall be ignored for
  8018.           collation purposes; for regular expression purposes they are
  8019.           ordered first.
  8020.  
  8021.      (2)  All characters between <space> and <a> shall have the same
  8022.           primary equivalence class and individual secondary weights based
  8023.           on their ordinal encoded values.
  8024.  
  8025.      (3)  All characters based on the upper- or lowercase character a
  8026.           belong to the same primary equivalence class.
  8027.  
  8028.      (4)  The multicharacter collating element <c><h> is represented by
  8029.           the collating symbol <ch> and belongs to the same primary
  8030.           equivalence class as the multicharacter collating element
  8031.           <C><h>.
  8032.  
  8033.      (5)  Note that it is not possible to use the collating element <ss>    1
  8034.           as a weight and expect it to be expanded to the string ``ss''.    1
  8035.           When used as a weight, any collating-element represents the       1
  8036.           relative order assigned to it in the character collation          1
  8037.           sequence, not the string from which it was derived (compare with  1
  8038.           <ch>).                                                            1
  8039.  
  8040.  
  8041.  
  8042.  
  8043.                Copyright c 1991 IEEE.  All rights reserved.
  8044.       This is an unapproved IEEE Standards Draft, subject to change.
  8045.  
  8046.  
  8047.  
  8048.  
  8049.  
  8050.  92                                 2 Terminology and General Requirements
  8051.  
  8052.  
  8053.  
  8054.  
  8055.  
  8056.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8057.  
  8058.  2.5.2.2.5  order_end Keyword
  8059.  
  8060.  The collating order entries shall be terminated with an order_end
  8061.  keyword.
  8062.  
  8063.  BEGIN_RATIONALE
  8064.  
  8065.  2.5.2.2.6  LC_COLLATE Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  8066.             _P_1_0_0_3._2)
  8067.  
  8068.  The LC_COLLATE category governs the collation order in the locale, and
  8069.  thus the processing of the C Standard {7} _s_t_r_x_f_r_m() and _s_t_r_c_o_l_l()
  8070.  functions, as well as a number of POSIX.2 utilities.
  8071.  
  8072.  The rules governing collation depends to some extent on the use.  At
  8073.  least five different levels of increasingly complex collation rules can
  8074.  be distinguished:
  8075.  
  8076.      (1)  Byte/machine code order.  This is the historical collation order
  8077.           in the UNIX system and many proprietary operating systems.
  8078.           Collation is here done character by character, without any
  8079.           regard to context.  The primary virtue is that it usually is
  8080.           quite fast, and also completely deterministic; it works well
  8081.           when the native machine collation sequence matches the user
  8082.           expectations.
  8083.  
  8084.      (2)  Character order.  On this level, collation is also done
  8085.           character by character, without regard to context.  The order
  8086.           between characters is, however, not determined by the code
  8087.           values, but on the user's expectations of the ``correct'' order
  8088.           between characters.  In addition, such a (simple) collation
  8089.           order can specify that certain characters collate equal (e.g.,
  8090.           upper- and lowercase letters).
  8091.  
  8092.      (3)  String ordering.  On this level, entire strings are compared
  8093.           based on relatively straightforward rules.  At this level,
  8094.           several ``passes'' may be required to determine the order
  8095.           between two strings.  Characters may be ignored in some passes,
  8096.           but not in others; the strings may be compared in different
  8097.           directions; and simple string substitutions may be made before
  8098.           strings are compared.  This level is best described as
  8099.           ``dictionary'' ordering; it is based on the spelling, not the
  8100.           pronunciation, or meaning, of the words.
  8101.  
  8102.      (4)  Text search ordering.  This is a further refinement of the
  8103.           previous level, best described as ``telephone book ordering'';    1
  8104.           some common homonyms (words spelled differently but with same     1
  8105.           pronunciation) are collated together; numbers are collated as if
  8106.           spelled with words, and so on.
  8107.  
  8108.  
  8109.                Copyright c 1991 IEEE.  All rights reserved.
  8110.       This is an unapproved IEEE Standards Draft, subject to change.
  8111.  
  8112.  
  8113.  
  8114.  
  8115.  
  8116.  2.5 Locale                                                             93
  8117.  
  8118.  
  8119.  
  8120.  
  8121.  
  8122.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8123.  
  8124.      (5)  Semantic level ordering.  Words and strings are collated based
  8125.           on their meaning; entire words (such as ``the'') are eliminated,
  8126.           the ordering is not deterministic.  This usually requires
  8127.           special software, and is highly dependent on the intended use.
  8128.  
  8129.  While the historical collation order formally is at level 1, for the
  8130.  English language it corresponds roughly to elements at level 2.  The user
  8131.  expects to see the output from the ls utility sorted very much as as it
  8132.  would be in a dictionary.  While telephone book ordering would be an
  8133.  optimal goal for standard collation, this was ruled out as the order
  8134.  would be language dependent.  Furthermore, a requirement was that the
  8135.  order must be determined solely from the text string and the collation
  8136.  rules; no external information (e.g., ``pronunciation dictionaries'')
  8137.  could be required.
  8138.  
  8139.  As a result, the goal for the collation support is at level 3.  This also
  8140.  matches the requirements for the proposed Canadian collation order, as
  8141.  well as other, known collation requirements for alphabetic scripts.  It
  8142.  specifically rules out collation based on pronunciation rules, or based
  8143.  on semantic analysis of the text.
  8144.  
  8145.  The syntax for the LC_COLLATE category source is the result of a
  8146.  cooperative effort between representatives for many countries and
  8147.  organizations working with international issues, such as UniForum,
  8148.  X/Open, and ISO, and it meets the requirements for level 3, and has been
  8149.  verified to produce the correct result with examples based on French,
  8150.  Canadian, and Danish collation order, as well as meeting the requirements
  8151.  in the X/Open Portability Guide, Issue 3.  {B31}.  Because it supports
  8152.  multicharacter collating elements, it is also capable of supporting
  8153.  collation in code sets where a character is expressed using nonspacing
  8154.  characters followed by the base character (such as ISO 6937 {B6}).
  8155.  
  8156.  The directives that can be specified in an operand to the order_start      2
  8157.  keyword are based on the requirements specified in several proposed        2
  8158.  standards and in customary use.  The following is a rephrasing of rules    2
  8159.  defined for ``lexical ordering in English and French'' by the Canadian     2
  8160.  Standards Association (text is brackets is rephrased):                     2
  8161.  
  8162.      (1)  Once special characters ([punctuation]) have been removed from    2
  8163.           original strings, the ordering is determined by scanning forward  2
  8164.           (left to right) [disregarding case and diacriticals].             2
  8165.  
  8166.      (2)  In case of equivalence, special characters are once again         2
  8167.           removed from original strings and the ordering is determined      2
  8168.           scanning backward (starting from the rightmost character of the   2
  8169.           string and back), character by character, [disregarding case but  2
  8170.           considering diacriticals].                                        2
  8171.  
  8172.  
  8173.  
  8174.  
  8175.                Copyright c 1991 IEEE.  All rights reserved.
  8176.       This is an unapproved IEEE Standards Draft, subject to change.
  8177.  
  8178.  
  8179.  
  8180.  
  8181.  
  8182.  94                                 2 Terminology and General Requirements
  8183.  
  8184.  
  8185.  
  8186.  
  8187.  
  8188.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8189.  
  8190.      (3)  In case of repeated equivalence, special characters are removed   2
  8191.           again from original strings and the ordering is determined        2
  8192.           scanning forward, character by character, [considering both case  2
  8193.           and diacriticals].                                                2
  8194.  
  8195.      (4)  If there is still an ordering equivalence after rules (1)         2
  8196.           through (3) have been applied, then only special characters and   2
  8197.           the position they occupy in the string are considered to          2
  8198.           determine ordering.  The string that has a special character in   2
  8199.           the lowest position comes first.  If two strings have a special   2
  8200.           character in the same position, the character [with the lowest    2
  8201.           collation value] comes first.  In case of equality, the other     2
  8202.           special characters are considered until there is a difference or  2
  8203.           all special characters have been exhausted.                       2
  8204.  
  8205.  It is estimated that the standard covers the requirements for all
  8206.  European languages, and no particular problems are anticipated with
  8207.  Slavic or Middle East character sets.
  8208.  
  8209.  The Far East (particularly Japanese/Chinese) collations are often based
  8210.  on contextual information and pronunciation rules (the same ideogram can
  8211.  have different meanings and different pronunciations).  Such collation,
  8212.  in general, falls outside the desired goal of the standard.  There are,
  8213.  however, several other collation rules (stroke/radical, or ``most common
  8214.  pronunciation'') which can be supported with the mechanism described
  8215.  here.
  8216.  
  8217.  Previous drafts contained a substitute statement, which performed a        2
  8218.  regular expression style replacement before string compares.  It has been  2
  8219.  withdrawn based on balloter objections that it was not required for the    2
  8220.  types of ordering POSIX.2 is aimed at.                                     2
  8221.  
  8222.  The character (and collating element) order is defined by the order in     2
  8223.  which characters and elements are specified between the order_start and    2
  8224.  order_end keywords.  This character order is used in range expressions in  2
  8225.  regular expressions (see 2.8).  Weights assigned to the characters and     2
  8226.  elements defines the collation sequence; in the absence of weights, the    2
  8227.  character order is also the collation sequence.                            2
  8228.  
  8229.  The position keyword was introduced to provide the capability to           1
  8230.  consider, in a compare, the relative position of non-IGNORE_d characters.   1
  8231.  As an example, consider the two strings ``o-ring'' and ``or-ing''.         1
  8232.  Assuming the hyphen is IGNORE_d on the first pass, the two strings will     1
  8233.  compare equal, and the position of the hyphen is immaterial.  On second    1
  8234.  pass, all characters except the hyphen are IGNORE_d, and in the normal      1
  8235.  case the two strings would again compare equal.  By taking position into   1
  8236.  account, the first collates before the second.                             1
  8237.  
  8238.  
  8239.  
  8240.  
  8241.                Copyright c 1991 IEEE.  All rights reserved.
  8242.       This is an unapproved IEEE Standards Draft, subject to change.
  8243.  
  8244.  
  8245.  
  8246.  
  8247.  
  8248.  2.5 Locale                                                             95
  8249.  
  8250.  
  8251.  
  8252.  
  8253.  
  8254.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8255.  
  8256.  END_RATIONALE                                                              1
  8257.  
  8258.  
  8259.  2.5.2.3  LC_MONETARY
  8260.  
  8261.      Table 2-8  -  LC_MONETARY Category Definition in the POSIX Locale
  8262.  __________________________________________________________________________________________________________________________________________________
  8263.  LC_MONETARY
  8264.  # This is the POSIX Locale definition for
  8265.  # the LC_MONETARY category.
  8266.  #
  8267.  int_curr_symbol         ""
  8268.  currency_symbol         ""
  8269.  mon_decimal_point       ""
  8270.  mon_thousands_sep       ""
  8271.  mon_grouping            ""
  8272.  positive_sign           ""
  8273.  negative_sign           ""
  8274.  int_frac_digits         -1
  8275.  p_cs_precedes           -1
  8276.  p_sep_by_space          -1
  8277.  n_cs_precedes           -1
  8278.  n_sep_by_space          -1
  8279.  p_sign_posn             -1
  8280.  n_sign_posn             -1
  8281.  #
  8282.  END LC_MONETARY
  8283.  __________________________________________________________________________________________________________________________________________________
  8284.  
  8285.  The LC_MONETARY category shall define the rules and symbols that shall be
  8286.  used to format monetary numeric information.  The operands are strings.
  8287.  For some keywords, the strings can contain only integers.  Keywords that
  8288.  are not provided, string values set to the empty string (""), or integer   1
  8289.  keywords set to -1, shall be used to indicate that the value is            1
  8290.  unspecified.  The following keywords shall be recognized:
  8291.  
  8292.     copy                  Specify the name of an existing locale to be
  8293.                           used as the source for the definition of this
  8294.                           category.  If this keyword is specified, no
  8295.                           other keyword shall be specified.
  8296.  
  8297.     int_curr_symbol       The international currency symbol.  The operand
  8298.                           shall be a four-character string, with the first
  8299.                           three characters containing the alphabetic
  8300.                           international currency symbol in accordance with
  8301.                           those specified in ISO 4217 {3} (_C_o_d_e_s _f_o_r _t_h_e
  8302.                           _r_e_p_r_e_s_e_n_t_a_t_i_o_n _o_f _c_u_r_r_e_n_c_i_e_s _a_n_d _f_u_n_d_s).  The
  8303.                           fourth character shall be the character used to
  8304.                           separate the international currency symbol from
  8305.                           the monetary quantity.
  8306.  
  8307.                Copyright c 1991 IEEE.  All rights reserved.
  8308.       This is an unapproved IEEE Standards Draft, subject to change.
  8309.  
  8310.  
  8311.  
  8312.  
  8313.  
  8314.  96                                 2 Terminology and General Requirements
  8315.  
  8316.  
  8317.  
  8318.  
  8319.  
  8320.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8321.  
  8322.     currency_symbol       The string that shall be used as the local
  8323.                           currency symbol.
  8324.  
  8325.     mon_decimal_point     The operand is a string containing the symbol     2
  8326.                           that shall be used as the decimal delimiter in    2
  8327.                           monetary formatted quantities.  In contexts       2
  8328.                           where other standards limit the                   2
  8329.                           mon_decimal_point to a single byte, the result    2
  8330.                           of specifying a multibyte operand is              2
  8331.                           unspecified.                                      2
  8332.  
  8333.     mon_thousands_sep     The operand is a string containing the symbol     2
  8334.                           that shall be used as a separator for groups of   2
  8335.                           digits to the left of the decimal delimiter in    2
  8336.                           formatted monetary quantities.  In contexts       2
  8337.                           where other standards limit the                   2
  8338.                           mon_thousands_sep to a single byte, the result    2
  8339.                           of specifying a multibyte operand is              2
  8340.                           unspecified.                                      2
  8341.  
  8342.     mon_grouping          Define the size of each group of digits in
  8343.                           formatted monetary quantities.  The operand is a
  8344.                           sequence of integers separated by semicolons.
  8345.                           Each integer specifies the number of digits in
  8346.                           each group, with the initial integer defining
  8347.                           the size of the group immediately preceding the
  8348.                           decimal delimiter, and the following integers
  8349.                           defining the preceding groups.  If the last       2
  8350.                           integer is not -1, then the size of the previous  2
  8351.                           group (if any) shall be repeatedly used for the   2
  8352.                           remainder of the digits.  If the last integer is  2
  8353.                           -1, then no further grouping shall be performed.  2
  8354.  
  8355.     positive_sign         A string that shall be used to indicate a
  8356.                           nonnegative-valued formatted monetary quantity.
  8357.  
  8358.     negative_sign         A string that shall be used to indicate a
  8359.                           negative-valued formatted monetary quantity.
  8360.  
  8361.     int_frac_digits       An integer representing the number of fractional
  8362.                           digits (those to the right of the decimal
  8363.                           delimiter) to be written in a formatted monetary
  8364.                           quantity using int_curr_symbol.
  8365.  
  8366.     frac_digits           An integer representing the number of fractional
  8367.                           digits (those to the right of the decimal
  8368.                           delimiter) to be written in a formatted monetary
  8369.                           quantity using currency_symbol.
  8370.  
  8371.  
  8372.  
  8373.                Copyright c 1991 IEEE.  All rights reserved.
  8374.       This is an unapproved IEEE Standards Draft, subject to change.
  8375.  
  8376.  
  8377.  
  8378.  
  8379.  
  8380.  2.5 Locale                                                             97
  8381.  
  8382.  
  8383.  
  8384.  
  8385.  
  8386.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8387.  
  8388.     p_cs_precedes         An integer set to 1 if the currency_symbol or
  8389.                           int_curr_symbol precedes the value for a
  8390.                           nonnegative formatted monetary quantity, and set
  8391.                           to 0 if the symbol succeeds the value.
  8392.  
  8393.     p_sep_by_space        An integer set to 0 if no space separates the
  8394.                           currency_symbol or int_curr_symbol from the
  8395.                           value for a nonnegative formatted monetary
  8396.                           quantity, set to 1 if a space separates the
  8397.                           symbol from the value, and set to 2 if a space
  8398.                           separates the symbol and the sign string, if
  8399.                           adjacent.
  8400.  
  8401.     n_cs_precedes         An integer set to 1 if the currency_symbol or
  8402.                           int_curr_symbol precedes the value for a
  8403.                           negative formatted monetary quantity, and set to
  8404.                           0 if the symbol succeeds the value.
  8405.  
  8406.     n_sep_by_space        An integer set to 0 if no space separates the
  8407.                           currency_symbol or int_curr_symbol from the
  8408.                           value for a negative formatted monetary
  8409.                           quantity, set to 1 if a space separates the
  8410.                           symbol from the value, and set to 2 if a space
  8411.                           separates the symbol and the sign string, if
  8412.                           adjacent.
  8413.  
  8414.     p_sign_posn           An integer set to a value indicating the
  8415.                           positioning of the positive_sign for a
  8416.                           nonnegative formatted monetary quantity.  The
  8417.                           following integer values shall be recognized:
  8418.  
  8419.                              0  Parentheses enclose the quantity and the
  8420.                                 currency_symbol or int_curr_symbol.
  8421.  
  8422.                              1  The sign string precedes the quantity and
  8423.                                 the currency_symbol or int_curr_symbol.
  8424.  
  8425.                              2  The sign string succeeds the quantity and
  8426.                                 the currency_symbol or int_curr_symbol.
  8427.  
  8428.                              3  The sign string immediately precedes the
  8429.                                 currency_symbol or int_curr_symbol.
  8430.  
  8431.                              4  The sign string immediately succeeds the
  8432.                                 currency_symbol or int_curr_symbol.
  8433.  
  8434.     n_sign_posn           An integer set to a value indicating the
  8435.                           positioning of the negative_sign for a negative   1
  8436.                           formatted monetary quantity.  The following
  8437.  
  8438.  
  8439.                Copyright c 1991 IEEE.  All rights reserved.
  8440.       This is an unapproved IEEE Standards Draft, subject to change.
  8441.  
  8442.  
  8443.  
  8444.  
  8445.  
  8446.  98                                 2 Terminology and General Requirements
  8447.  
  8448.  
  8449.  
  8450.  
  8451.  
  8452.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8453.  
  8454.                           integer values shall be recognized:
  8455.  
  8456.                              0  Parentheses enclose the quantity and the
  8457.                                 currency_symbol or int_curr_symbol.
  8458.  
  8459.                              1  The sign string precedes the quantity and
  8460.                                 the currency_symbol or int_curr_symbol.
  8461.  
  8462.                              2  The sign string succeeds the quantity and
  8463.                                 the currency_symbol or int_curr_symbol.
  8464.  
  8465.                              3  The sign string immediately precedes the
  8466.                                 currency_symbol or int_curr_symbol.
  8467.  
  8468.                              4  The sign string immediately succeeds the
  8469.                                 currency_symbol or int_curr_symbol.
  8470.  
  8471.  BEGIN_RATIONALE
  8472.  
  8473.  2.5.2.3.1  LC_MONETARY Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  8474.             _P_1_0_0_3._2)
  8475.  
  8476.  The currency symbol does not appear in LC_MONETARY because it is not
  8477.  defined in the C Standard's {7} C locale.
  8478.  
  8479.  The C Standard {7} limits the size of decimal points and thousands         2
  8480.  delimiters to single-byte values.  In locales based on multibyte coded     2
  8481.  character sets this cannot be enforced, obviously; this standard does not  2
  8482.  prohibit such characters, but makes the behavior unspecified [in the text  2
  8483.  ``In contexts where other standards ...''].                                2
  8484.  
  8485.  The grouping specification is based on, but not identical to, the          2
  8486.  C Standard {7}.  The ``-1'' signals that no further grouping shall be      2
  8487.  performed, the equivalent of {CHAR_MAX} in the C Standard {7}).            2
  8488.  
  8489.  The locale definition is an extension of the C Standard {7} _l_o_c_a_l_e_c_o_n_v()
  8490.  specification.  In particular, rules on how currency_symbol is treated
  8491.  are extended to also cover int_curr_symbol, and p_set_by_space and
  8492.  n_sep_by_space have been augmented with the value 2, which places a space
  8493.  between the sign and the symbol (if they are adjacent; otherwise it
  8494.  should be treated as a 0).  The following table shows the result of
  8495.  various combinations:
  8496.  
  8497.  
  8498.  
  8499.  
  8500.  
  8501.  
  8502.  
  8503.  
  8504.  
  8505.                Copyright c 1991 IEEE.  All rights reserved.
  8506.       This is an unapproved IEEE Standards Draft, subject to change.
  8507.  
  8508.  
  8509.  
  8510.  
  8511.  
  8512.  2.5 Locale                                                             99
  8513.  
  8514.  
  8515.  
  8516.  
  8517.  
  8518.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8519.  
  8520.                                                  p_sep_by_space
  8521.                                              2          1          0
  8522.  
  8523.     p_cs_precedes = 1   p_sign_posn = 0   ($1.25)    ($ 1.25)   ($1.25)
  8524.                         p_sign_posn = 1   + $1.25    +$ 1.25    +$1.25
  8525.                         p_sign_posn = 2   $1.25 +    $ 1.25+    $1.25+
  8526.                         p_sign_posn = 3   + $1.25    +$ 1.25    +$1.25
  8527.                         p_sign_posn = 4   $ +1.25    $+ 1.25    $+1.25
  8528.  
  8529.     p_cs_precedes = 0   p_sign_posn = 0   (1.25 $)   (1.25 $)   (1.25$)
  8530.                         p_sign_posn = 1   +1.25 $    +1.25 $    +1.25$
  8531.                         p_sign_posn = 2   1.25$ +    1.25 $+    1.25$+
  8532.                         p_sign_posn = 3   1.25+ $    1.25 +$    1.25+$
  8533.                         p_sign_posn = 4   1.25$ +    1.25 $+    1.25$+
  8534.  
  8535.  The following is an example of the interpretation of the mon_grouping
  8536.  keyword.  Assuming that the value to be formatted is 123456789 and the
  8537.  mon_thousands_sep is ', then the following table shows the result.  The    1
  8538.  third column shows the equivalent C Standard {7} string that would be      1
  8539.  used to accommodate this grouping.  It is the responsibility of the        1
  8540.  utility to perform mappings of the formats in this clause to those used    1
  8541.  by language bindings such as the C Standard {7}.                           1
  8542.  
  8543.           mon_grouping   Formatted Value   C Standard {7} String            1
  8544.           ____________   _______________   _____________________            1
  8545.           3;-1           123456'789        "\3\177"                         2
  8546.           3              123'456'789       "\3"                             2
  8547.           3;2;-1         1234'56'789       "\3\2\177"                       2
  8548.           3;2            12'34'56'789      "\3\2"                           2
  8549.           -1             123456789         "177"                            2
  8550.  
  8551.  In these examples, the octal value of {CHAR_MAX} is 177.                   2
  8552.  
  8553.  END_RATIONALE
  8554.  
  8555.  2.5.2.4  LC_NUMERIC
  8556.  
  8557.  The LC_NUMERIC category shall define the rules and symbols that shall be
  8558.  used to format nonmonetary numeric information.  The operands are
  8559.  strings.  For some keywords, the strings only can contain integers.
  8560.  Keywords that are not provided, string values set to the empty string      1
  8561.  (""), or integer keywords set to -1, shall be used to indicate that the    1
  8562.  value is unspecified.  The following keywords shall be recognized:
  8563.  
  8564.     copy               Specify the name of an existing locale to be used
  8565.                        as the source for the definition of this category.
  8566.                        If this keyword is specified, no other keyword
  8567.                        shall be specified.
  8568.  
  8569.  
  8570.  
  8571.                Copyright c 1991 IEEE.  All rights reserved.
  8572.       This is an unapproved IEEE Standards Draft, subject to change.
  8573.  
  8574.  
  8575.  
  8576.  
  8577.  
  8578.  100                                2 Terminology and General Requirements
  8579.  
  8580.  
  8581.  
  8582.  
  8583.  
  8584.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8585.  
  8586.     decimal_point      The operand is a string containing the symbol that   2
  8587.                        shall be used as the decimal delimiter in numeric,   2
  8588.                        nonmonetary formatted quantities.  This keyword      2
  8589.                        cannot be omitted and cannot be set to the empty     2
  8590.                        string.  In contexts where other standards limit     2
  8591.                        the decimal_point to a single byte, the result of    2
  8592.                        specifying a multibyte operand is unspecified.       2
  8593.  
  8594.     thousands_sep      The operand is a string containing the symbol that   2
  8595.                        shall be used as a separator for groups of digits    2
  8596.                        to the left of the decimal delimiter in numeric,     2
  8597.                        nonmonetary formatted monetary quantities.  In       2
  8598.                        contexts where other standards limit the             2
  8599.                        thousands_sep to a single byte, the result of        2
  8600.                        specifying a multibyte operand is unspecified.       2
  8601.  
  8602.     grouping           Define the size of each group of digits in
  8603.                        formatted nonmonetary quantities.  The operand is a
  8604.                        sequence of integers separated by semicolons.  Each
  8605.                        integer specifies the number of digits in each
  8606.                        group, with the initial integer defining the size
  8607.                        of the group immediately preceding the decimal
  8608.                        delimiter, and the following integers defining the
  8609.                        preceding groups.  If the last integer is not -1,    2
  8610.                        then the size of the previous group (if any) shall   2
  8611.                        be repeatedly used for the remainder of the digits.  2
  8612.                        If the last integer is -1, then no further grouping  2
  8613.                        shall be performed.                                  2
  8614.  
  8615.      Table 2-9  -  LC_NUMERIC Category Definition in the POSIX Locale
  8616.  __________________________________________________________________________________________________________________________________________________
  8617.  LC_NUMERIC
  8618.  # This is the POSIX Locale definition for
  8619.  # the LC_NUMERIC category.
  8620.  #
  8621.  decimal_point           "<period>"                                         2
  8622.  thousands_sep           ""
  8623.  grouping                0
  8624.  #
  8625.  END LC_NUMERIC
  8626.  __________________________________________________________________________________________________________________________________________________
  8627.  
  8628.  BEGIN_RATIONALE
  8629.  
  8630.  
  8631.  
  8632.  
  8633.  
  8634.  
  8635.  
  8636.  
  8637.                Copyright c 1991 IEEE.  All rights reserved.
  8638.       This is an unapproved IEEE Standards Draft, subject to change.
  8639.  
  8640.  
  8641.  
  8642.  
  8643.  
  8644.  2.5 Locale                                                            101
  8645.  
  8646.  
  8647.  
  8648.  
  8649.  
  8650.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8651.  
  8652.  2.5.2.4.1  LC_NUMERIC Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  8653.             _P_1_0_0_3._2)
  8654.  
  8655.  See the rationale for LC_MONETARY (2.5.2.3.1) for a description of the     1
  8656.  behavior of grouping.                                                      1
  8657.  
  8658.  END_RATIONALE                                                              1
  8659.  
  8660.  
  8661.  2.5.2.5  LC_TIME
  8662.  
  8663.  The LC_TIME category shall define the interpretation of the field
  8664.  descriptors supported by the date utility (see 4.15).
  8665.  
  8666.       Table 2-10  -  LC_TIME Category Definition in the POSIX Locale
  8667.  __________________________________________________________________________________________________________________________________________________
  8668.  LC_TIME
  8669.  # This is the POSIX Locale definition for
  8670.  # the LC_TIME category.
  8671.  #
  8672.  # Abbreviated weekday names (%a)
  8673.  abday   "<S><u><n>";"<M><o><n>";"<T><u><e>";"<W><e><d>";\
  8674.          "<T><h><u>";"<F><r><i>";"<S><a><t>"
  8675.  #
  8676.  # Full weekday names (%A)
  8677.  day     "<S><u><n><d><a><y>";"<M><o><n><d><a><y>";\
  8678.          "<T><u><e><s><d><a><y>";"<W><e><d><n><e><s><d><a><y>";\
  8679.          "<T><h><u><r><s><d><a><y>";"<F><r><i><d><a><y>";\
  8680.          "<S><a><t><u><r><d><a><y>"
  8681.  #
  8682.  # Abbreviated month names (%b)
  8683.  abmon   "<J><a><n>";"<F><e><b>";"<M><a><r>";\
  8684.          "<A><p><r>";"<M><a><y>";"<J><u><n>";\
  8685.          "<J><u><l>";"<A><u><g>";"<S><e><p>";\
  8686.          "<O><c><t>";"<N><o><v>";"<D><e><c>"
  8687.  #
  8688.  # Full month names (%B)
  8689.  mon     "<J><a><n><u><a><r><y>";"<F><e><b><r><u><a><r><y>";\
  8690.          "<M><a><r><c><h>";"<A><p><r><i><l>";\
  8691.          "<M><a><y>";"<J><u><n><e>";\
  8692.          "<J><u><l><y>";"<A><u><g><u><s><t>";\
  8693.          "<S><e><p><t><e><m><b><e><r>";"<O><c><t><o><b><e><r>";\
  8694.          "<N><o><v><e><m><b><e><r>";"<D><e><c><e><m><b><e><r>"
  8695.  #
  8696.  # Equivalent of AM/PM (%p)      "AM";"PM"
  8697.  am_pm   "<A><M>";"<P><M>"
  8698.  #
  8699.  # Appropriate date and time representation (%c)
  8700.  #       "%a %b %e %H:%M:%S %Y"                                             1
  8701.  d_t_fmt "<percent-sign><a><space><percent-sign><b><space><percent-sign><e>\1
  8702.  
  8703.                Copyright c 1991 IEEE.  All rights reserved.
  8704.       This is an unapproved IEEE Standards Draft, subject to change.
  8705.  
  8706.  
  8707.  
  8708.  
  8709.  
  8710.  102                                2 Terminology and General Requirements
  8711.  
  8712.  
  8713.  
  8714.  
  8715.  
  8716.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8717.  
  8718.  <space><percent-sign><H><colon><percent-sign><M>\
  8719.  <colon><percent-sign><S><space><percent-sign><Y>"
  8720.  #
  8721.  # Appropriate date representation (%x)   "%m/%d/%y"
  8722.  d_fmt   "<percent-sign><m><slash><percent-sign><d><slash><percent-sign><y>"
  8723.  #
  8724.  # Appropriate time representation (%X)   "%H:%M:%S"
  8725.  t_fmt   "<percent-sign><H><colon><percent-sign><M><colon><percent-sign><S>"
  8726.  #
  8727.  # Appropriate 12-hour time representation (%r) "%I:%M:%S %p"
  8728.  t_fmt_ampm "<percent-sign><I><colon><percent-sign><M><colon>\
  8729.  <percent-sign><S> <percent_sign><p>"
  8730.  #
  8731.  END LC_TIME
  8732.  
  8733.  __________________________________________________________________________________________________________________________________________________
  8734.  
  8735.  
  8736.  
  8737.  
  8738.  The following mandatory keywords shall be recognized:
  8739.  
  8740.     copy       Specify the name of an existing locale to be used as the
  8741.                source for the definition of this category.  If this
  8742.                keyword is specified, no other keyword shall be specified.
  8743.  
  8744.     abday      Define the abbreviated weekday names, corresponding to the
  8745.                %a field descriptor.  The operand shall consist of seven
  8746.                semicolon-separated strings.  The first string shall be the
  8747.                abbreviated name of the first day of the week (Sunday), the
  8748.                second the abbreviated name of the second day, and so on.
  8749.  
  8750.     day        Define the full weekday names, corresponding to the %A
  8751.                field descriptor.  The operand shall consist of seven
  8752.                semicolon-separated strings.  The first string shall be the
  8753.                full name of the first day of the week (Sunday), the second
  8754.                the full name of the second day, and so on.
  8755.  
  8756.     abmon      Define the abbreviated month names, corresponding to the %b
  8757.                field descriptor.  The operand shall consist of twelve
  8758.                semicolon-separated strings.  The first string shall be the
  8759.                abbreviated name of the first month of the year (January),
  8760.                the second the abbreviated name of the second month, and so
  8761.                on.
  8762.  
  8763.     mon        Define the full month names, corresponding to the %B field
  8764.                descriptor.  The operand shall consist of twelve
  8765.                semicolon-separated strings.  The first string shall be the
  8766.                full name of the first month of the year (January), the
  8767.  
  8768.  
  8769.                Copyright c 1991 IEEE.  All rights reserved.
  8770.       This is an unapproved IEEE Standards Draft, subject to change.
  8771.  
  8772.  
  8773.  
  8774.  
  8775.  
  8776.  2.5 Locale                                                            103
  8777.  
  8778.  
  8779.  
  8780.  
  8781.  
  8782.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8783.  
  8784.                second the full name of the second month, and so on.
  8785.  
  8786.     d_t_fmt    Define the appropriate date and time representation,
  8787.                corresponding to the %c field descriptor.  The operand
  8788.                shall consist of a string, and can contain any combination
  8789.                of characters and field descriptors.  In addition, the
  8790.                string can contain escape sequences defined in Table 2-15.   1
  8791.  
  8792.     d_fmt      Define the appropriate date representation, corresponding
  8793.                to the %x field descriptor.  The operand shall consist of a
  8794.                string, and can contain any combination of characters and
  8795.                field descriptors.  In addition, the string can contain
  8796.                escape sequences defined in Table 2-15.                      1
  8797.  
  8798.     t_fmt      Define the appropriate time representation, corresponding
  8799.                to the %X field descriptor.  The operand shall consist of a
  8800.                string, and can contain any combination of characters and
  8801.                field descriptors.  In addition, the string can contain
  8802.                escape sequences defined in Table 2-15.                      1
  8803.  
  8804.     am_pm      Define the appropriate representation of the _a_n_t_e _m_e_r_i_d_i_e_m
  8805.                and _p_o_s_t _m_e_r_i_d_i_e_m strings, corresponding to the %p field
  8806.                descriptor.  The operand shall consist of two strings,
  8807.                separated by a semicolon.  The first string shall represent
  8808.                the _a_n_t_e _m_e_r_i_d_i_e_m designation, the last string the _p_o_s_t
  8809.                _m_e_r_i_d_i_e_m designation.
  8810.  
  8811.     t_fmt_ampm
  8812.                Define the appropriate time representation in the 12-hour
  8813.                clock format with am_pm, corresponding to the %r field
  8814.                descriptor.  The operand shall consist of a string and can
  8815.                contain any combination of characters and field
  8816.                descriptors.  If the string is empty, the 12-hour format is
  8817.                not supported in the locale.
  8818.  
  8819.  It is implementation defined whether the following optional keywords
  8820.  shall be recognized.  If they are not supported, but present in a
  8821.  localedef source, they shall be ignored.
  8822.  
  8823.     era            Shall be used to define alternate Eras, corresponding
  8824.                    to the %E field descriptor modifier.  The format of the
  8825.                    operand is unspecified, but shall support the
  8826.                    definition of the %EC and %Ey field descriptors, and
  8827.                    may also define the era_year format (%EY).
  8828.  
  8829.     era_year       Shall be used to define the format of the year in
  8830.                    alternate Era format, corresponding to the %EY field
  8831.                    descriptor.
  8832.  
  8833.  
  8834.  
  8835.                Copyright c 1991 IEEE.  All rights reserved.
  8836.       This is an unapproved IEEE Standards Draft, subject to change.
  8837.  
  8838.  
  8839.  
  8840.  
  8841.  
  8842.  104                                2 Terminology and General Requirements
  8843.  
  8844.  
  8845.  
  8846.  
  8847.  
  8848.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8849.  
  8850.     era_d_fmt      Shall be used to define the format of the date in
  8851.                    alternate Era notation, corresponding to the %Ex field
  8852.                    descriptor.
  8853.  
  8854.     alt_digits     Shall be used to define alternate symbols for digits,
  8855.                    corresponding to the %O field descriptor modifier.  The
  8856.                    operand shall consist of semicolon-separated strings.
  8857.                    The first string shall be the alternate symbol
  8858.                    corresponding with zero, the second string the symbol
  8859.                    corresponding with one, and so on.  Up to 100 alternate
  8860.                    symbol strings can be specified.  The %O modifier
  8861.                    indicates that the string corresponding to the value
  8862.                    specified via the field descriptor shall be used
  8863.                    instead of the value.
  8864.  
  8865.  BEGIN_RATIONALE
  8866.  
  8867.  2.5.2.5.1  LC_TIME Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  8868.  
  8869.  Although certain of the field descriptors in the POSIX Locale (such as
  8870.  the name of the month) are shown with initial capital letters, this need
  8871.  not be the case in other locales.  Programs using these fields may need
  8872.  to adjust the capitalization if the output is going to be used at the
  8873.  beginning of a sentence.
  8874.  
  8875.  The LC_TIME descriptions of abday, daya, and abmon imply a Gregorian       1
  8876.  style calendar (7-day weeks, 12-month years, leap years, etc.).            1
  8877.  Formatting time strings for other types of calendars is outside the scope  1
  8878.  of this standard.                                                          1
  8879.  
  8880.  As specified under the date command, the field descriptors corresponding
  8881.  to the optional keywords consist of a modifier followed by a traditional
  8882.  field descriptor (for instance %Ex).  If the optional keywords are not
  8883.  supported by the implementation or are unspecified for the current
  8884.  locale, these field descriptors shall be treated as the traditional field
  8885.  descriptor.  For instance, assume the following keywords:
  8886.  
  8887.        alt_digits      "0th";"1st";"2nd";"3rd";"4th";"5th";\                1
  8888.                        "6th";"7th";"8th";"9th";"10th"                       1
  8889.  
  8890.        d_fmt           "The %Od day of %B in %Y"                            1
  8891.  
  8892.  On 7/4/1776, the %x field descriptor would result in ``The 4th day of      1
  8893.  July in 1776,'' while 7/14/1789 would come out as ``The 14 day of July in
  8894.  1789.''  It can be noted that the above example is for illustrative
  8895.  purposes only; the %O modifier is primarily intended to provide for Kanji
  8896.  or Hindi digits in date formats.
  8897.  
  8898.  
  8899.  
  8900.  
  8901.                Copyright c 1991 IEEE.  All rights reserved.
  8902.       This is an unapproved IEEE Standards Draft, subject to change.
  8903.  
  8904.  
  8905.  
  8906.  
  8907.  
  8908.  2.5 Locale                                                            105
  8909.  
  8910.  
  8911.  
  8912.  
  8913.  
  8914.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  8915.  
  8916.  While it is clear that an alternate year format is required, there is no
  8917.  consensus on the format or the requirements.  As a result, while these
  8918.  keywords are reserved, the details are left unspecified.  It is expected
  8919.  that National Standards Bodies will provide specifications.
  8920.  
  8921.  END_RATIONALE
  8922.  
  8923.  
  8924.  2.5.2.6  LC_MESSAGES
  8925.  
  8926.  The LC_MESSAGES category shall define the format and values for
  8927.  affirmative and negative responses.  The operands shall be strings or
  8928.  extended regular expressions; see 2.8.4.  The following keywords shall be
  8929.  recognized:
  8930.  
  8931.     copy       Specify the name of an existing locale to be used as the
  8932.                source for the definition of this category.  If this
  8933.                keyword is specified, no other keyword shall be specified.
  8934.  
  8935.     yesexpr    The operand shall consist of an extended regular expression
  8936.                that describes the acceptable affirmative response to a
  8937.                question expecting an affirmative or negative response.
  8938.  
  8939.     noexpr     The operand shall consist of an extended regular expression
  8940.                that describes the acceptable negative response to a
  8941.                question expecting an affirmative or negative response.
  8942.  
  8943.     Table 2-11  -  LC_MESSAGES Category Definition in the POSIX Locale
  8944.  __________________________________________________________________________________________________________________________________________________
  8945.  LC_MESSAGES
  8946.  # This is the POSIX Locale definition for
  8947.  # the LC_MESSAGES category.
  8948.  #
  8949.  yesexpr "<circumflex><left-square-bracket><y><Y><right-square-bracket>"
  8950.  #
  8951.  noexpr  "<circumflex><left-square-bracket><n><N><right-square-bracket>"
  8952.  END LC_MESSAGES
  8953.  __________________________________________________________________________________________________________________________________________________
  8954.  
  8955.  
  8956.  BEGIN_RATIONALE
  8957.  
  8958.  2.5.2.6.1  LC_MESSAGES Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  8959.             _P_1_0_0_3._2)
  8960.  
  8961.  The LC_MESSAGES category is described in 2.6 as affecting the language
  8962.  used by utilities for their output.  The mechanism used by the
  8963.  implementation to accomplish this, other than the responses shown here in
  8964.  the locale definition file, is not specified by this version of this
  8965.  standard.  The POSIX.1 working group is developing an interface that
  8966.  
  8967.                Copyright c 1991 IEEE.  All rights reserved.
  8968.       This is an unapproved IEEE Standards Draft, subject to change.
  8969.  
  8970.  
  8971.  
  8972.  
  8973.  
  8974.  106                                2 Terminology and General Requirements
  8975.  
  8976.  
  8977.  
  8978.  
  8979.  
  8980.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  8981.  
  8982.  would allow applications (and, presumably some of the standard utilities)
  8983.  to access messages from various message catalogs, tailored to a user's
  8984.  LC_MESSAGES value.
  8985.  
  8986.  END_RATIONALE
  8987.  
  8988.  
  8989.  2.5.3  Locale Definition Grammar                                           1
  8990.  
  8991.  The grammar and lexical conventions in this subclause shall together       1
  8992.  describe the syntax for the locale definition source.  The general         1
  8993.  conventions for this style of grammar are described in 2.1.2.  Any         1
  8994.  discrepancies found between this grammar and other descriptions in this    1
  8995.  clause shall be resolved in favor of this grammar.                         1
  8996.  
  8997.  
  8998.  2.5.3.1  Locale Lexical Conventions                                        1
  8999.  
  9000.  The lexical conventions for the locale definition grammar are described    1
  9001.  in this subclause.                                                         1
  9002.  
  9003.  The following tokens shall be processed (in addition to those string       1
  9004.  constants shown in the grammar):                                           1
  9005.  
  9006.     LOC_NAME       A string of characters representing the name of a        1
  9007.                    locale.                                                  1
  9008.  
  9009.     CHAR           Any single character.                                    1
  9010.  
  9011.     NUMBER         A decimal number, represented by one or more decimal     2
  9012.                    digits.                                                  2
  9013.  
  9014.     COLLSYMBOL     A symbolic name, enclosed between angle brackets.  The   1
  9015.                    string shall not duplicate any charmap symbol defined    1
  9016.                    in the current charmap (if any), or a COLLELEMENT        1
  9017.                    symbol.                                                  1
  9018.  
  9019.     COLLELEMENT    A symbolic name, enclosed between angle brackets, which  1
  9020.                    shall not duplicate either any charmap symbol or a       1
  9021.                    CHARSYMBOL symbol.                                       1
  9022.  
  9023.     CHARSYMBOL     A symbolic name, enclosed between angle brackets, from   1
  9024.                    the current charmap (if any).                            1
  9025.  
  9026.     OCTAL_CHAR     One or more octal representations of the encoding of     1
  9027.                    each byte in a single character.  The octal              1
  9028.                    representation consists of an escape_char (normally a    1
  9029.                    backslash) followed by two or more octal digits.         1
  9030.  
  9031.  
  9032.  
  9033.                Copyright c 1991 IEEE.  All rights reserved.
  9034.       This is an unapproved IEEE Standards Draft, subject to change.
  9035.  
  9036.  
  9037.  
  9038.  
  9039.  
  9040.  2.5 Locale                                                            107
  9041.  
  9042.  
  9043.  
  9044.  
  9045.  
  9046.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9047.  
  9048.     HEX_CHAR       One or more hexadecimal representations of the encoding  1
  9049.                    of each byte in a single character.  The hexadecimal     1
  9050.                    representation consists of an escape_char followed by    1
  9051.                    the constant 'x' and two or more hexadecimal digits.     1
  9052.  
  9053.     DECIMAL_CHAR   One or more decimal representations of the encoding of   1
  9054.                    each byte in a single character.  The decimal            1
  9055.                    representation consists of an escape_char and followed   1
  9056.                    by a 'd' and two or more decimal digits.                 1
  9057.  
  9058.     ELLIPSIS       The string ``...''.                                      1
  9059.  
  9060.                                                                             2
  9061.  
  9062.     EXTENDED_REG_EXP                                                        1
  9063.                    An extended regular expression as defined in the         1
  9064.                    grammar in 2.8.5.2.                                      1
  9065.  
  9066.                                                                             2
  9067.  
  9068.     EOL            The line termination character <newline>.                1
  9069.  
  9070.  
  9071.  2.5.3.2  Locale Grammar                                                    1
  9072.  
  9073.  This subclause presents the grammar for the locale definition.             1
  9074.  
  9075.  %token          LOC_NAME                                                   1
  9076.  %token          CHAR                                                       1
  9077.  %token          NUMBER                                                     2
  9078.  %token          COLLSYMBOL COLLELEMENT                                     1
  9079.  %token          CHARSYMBOL OCTAL_CHAR HEX_CHAR DECIMAL_CHAR                1
  9080.  %token          ELLIPSIS                                                   1
  9081.  %token          EXTENDED_REG_EXP                                           2
  9082.  %token          EOL                                                        1
  9083.  
  9084.  %start  locale_definition                                                  1
  9085.  
  9086.  %%                                                                         1
  9087.  
  9088.  locale_definition       : global_statements locale_categories              2
  9089.                          |                   locale_categories              2
  9090.                          ;                                                  1
  9091.  
  9092.  global_statements       : global_statements symbol_redefine                2
  9093.                          | symbol_redefine                                  2
  9094.                          ;                                                  1
  9095.  
  9096.  
  9097.  
  9098.  
  9099.                Copyright c 1991 IEEE.  All rights reserved.
  9100.       This is an unapproved IEEE Standards Draft, subject to change.
  9101.  
  9102.  
  9103.  
  9104.  
  9105.  
  9106.  108                                2 Terminology and General Requirements
  9107.  
  9108.  
  9109.  
  9110.  
  9111.  
  9112.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9113.  
  9114.  symbol_redefine         : '#escape_char'  CHAR EOL                         1
  9115.                          | '#comment_char' CHAR EOL                         1
  9116.                          ;                                                  1
  9117.  
  9118.  locale_categories       : locale_categories locale_category                2
  9119.                          | locale_category                                  2
  9120.                          ;                                                  1
  9121.  
  9122.  locale_category         : lc_ctype | lc_collate | lc_messages              1
  9123.                          | lc_monetary | lc_numeric | lc_time               1
  9124.                          ;                                                  1
  9125.  
  9126.  /*      The following grammar rules are common to all categories */        1
  9127.  
  9128.  char_list               : char_list char_symbol                            2
  9129.                          | char_symbol                                      2
  9130.                          ;                                                  1
  9131.  
  9132.  char_symbol             : CHAR | CHARSYMBOL                                1
  9133.                          | OCTAL_CHAR | HEX_CHAR | DECIMAL_CHAR             1
  9134.                          ;                                                  1
  9135.  
  9136.  locale_name             : LOC_NAME                                         1
  9137.                          | '"' LOC_NAME '"'                                 1
  9138.                          ;                                                  1
  9139.  
  9140.  /*      The following is the LC_CTYPE category grammar */                  1
  9141.  
  9142.  lc_ctype                : ctype_hdr ctype_keywords         ctype_tlr       2
  9143.                          | ctype_hdr 'copy' locale_name EOL ctype_tlr       2
  9144.                          ;                                                  2
  9145.  
  9146.  ctype_hdr               : 'LC_CTYPE' EOL                                   2
  9147.                          ;                                                  2
  9148.  
  9149.  ctype_keywords          : ctype_keywords ctype_keyword                     2
  9150.                          | ctype_keyword                                    2
  9151.                          ;                                                  1
  9152.  
  9153.  ctype_keyword           : charclass_keyword charclass_list EOL             1
  9154.                          | charconv_keyword charconv_list EOL               1
  9155.                          ;                                                  1
  9156.  
  9157.  charclass_keyword       : 'upper' | 'lower' | 'alpha' | 'digit'            1
  9158.                          | 'alnum' | 'xdigit' | 'space' | 'print'           1
  9159.                          | 'graph' | 'blank' | 'cntrl'                      1
  9160.                          ;                                                  1
  9161.  
  9162.  
  9163.  
  9164.  
  9165.                Copyright c 1991 IEEE.  All rights reserved.
  9166.       This is an unapproved IEEE Standards Draft, subject to change.
  9167.  
  9168.  
  9169.  
  9170.  
  9171.  
  9172.  2.5 Locale                                                            109
  9173.  
  9174.  
  9175.  
  9176.  
  9177.  
  9178.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9179.  
  9180.  charclass_list          : charclass_list ';' char_symbol                   2
  9181.                          | charclass_list ';' ELLIPSIS ';' char_symbol      1
  9182.                          | char_symbol                                      2
  9183.                          ;                                                  1
  9184.  
  9185.  charconv_keyword        : 'toupper'                                        1
  9186.                          | 'tolower'                                        1
  9187.                          ;                                                  1
  9188.  
  9189.  charconv_list           : charconv_list ';' charconv_entry                 2
  9190.                          | charconv_entry                                   2
  9191.                          ;                                                  1
  9192.  
  9193.  charconv_entry          : '(' char_symbol ',' char_symbol ')'              1
  9194.                          ;                                                  1
  9195.  
  9196.  ctype_tlr               : 'END' 'LC_CTYPE' EOL                             2
  9197.                          ;                                                  1
  9198.  
  9199.  /*      The following is the LC_COLLATE category grammar */                1
  9200.  
  9201.  lc_collate              : collate_hdr collate_keywords       collate_tlr   2
  9202.                          | collate_hdr 'copy' locale_name EOL collate_tlr   2
  9203.                          ;                                                  2
  9204.  
  9205.  collate_hdr             : 'LC_COLLATE' EOL                                 2
  9206.                          ;                                                  2
  9207.  
  9208.  collate_keywords        :                order_statements                  2
  9209.                          | opt_statements order_statements                  2
  9210.                          ;                                                  1
  9211.  
  9212.  opt_statements          : opt_statements collating_symbols                 2
  9213.                          | opt_statements collating_elements                2
  9214.                          | collating_symbols                                1
  9215.                          | collating_elements                               1
  9216.                          ;                                                  1
  9217.  
  9218.  collating_symbols       : 'collating-symbol' COLLSYMBOL EOL                1
  9219.                          ;                                                  1
  9220.  
  9221.  collating_elements      : 'collating-element' COLLELEMENT                  1
  9222.                            'from' '"' char_list '"' EOL                     2
  9223.                          ;                                                  1
  9224.                                                                             2
  9225.  
  9226.  order_statements        : order_start collation_order order_end            1
  9227.                          ;                                                  1
  9228.  
  9229.  
  9230.  
  9231.                Copyright c 1991 IEEE.  All rights reserved.
  9232.       This is an unapproved IEEE Standards Draft, subject to change.
  9233.  
  9234.  
  9235.  
  9236.  
  9237.  
  9238.  110                                2 Terminology and General Requirements
  9239.  
  9240.  
  9241.  
  9242.  
  9243.  
  9244.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9245.  
  9246.  order_start             : 'order_start' EOL                                1
  9247.                          | 'order_start' order_opts EOL                     1
  9248.                          ;                                                  1
  9249.  
  9250.  order_opts              : order_opts ';' order_opt                         2
  9251.                          | order_opt                                        2
  9252.                          ;                                                  1
  9253.  
  9254.  order_opt               : order_opt ',' opt_word                           2
  9255.                          | opt_word                                         2
  9256.                          ;                                                  1
  9257.  
  9258.  opt_word                : 'forward' | 'backward' | 'position'              2
  9259.                          ;                                                  1
  9260.  
  9261.  collation_order         : collation_order collation_entry                  2
  9262.                          | collation_entry                                  2
  9263.                          ;                                                  1
  9264.  
  9265.  collation_entry         : COLLSYMBOL EOL                                   1
  9266.                          | collation_element weight_list EOL                1
  9267.                          | collation_element             EOL                2
  9268.                          ;                                                  1
  9269.  
  9270.  collation_element       : char_symbol                                      1
  9271.                          | COLLELEMENT                                      1
  9272.                          | ELLIPSIS                                         1
  9273.                          | 'UNDEFINED'                                      1
  9274.                          ;                                                  1
  9275.  
  9276.  weight_list             : weight_list ';' weight_symbol                    2
  9277.                          | weight_list ';'                                  2
  9278.                          | weight_symbol                                    2
  9279.                          ;                                                  1
  9280.  
  9281.  weight_symbol           : char_symbol                                      2
  9282.                          | COLLSYMBOL                                       1
  9283.                          | '"' char_list '"'                                1
  9284.                          | ELLIPSIS                                         1
  9285.                          | 'IGNORE'                                         1
  9286.                          ;                                                  1
  9287.  
  9288.  order_end               : 'order_end' EOL                                  1
  9289.                          ;                                                  1
  9290.  
  9291.  collate_tlr             : 'END' 'LC_COLLATE' EOL                           2
  9292.                          ;                                                  1
  9293.  
  9294.  
  9295.  
  9296.  
  9297.                Copyright c 1991 IEEE.  All rights reserved.
  9298.       This is an unapproved IEEE Standards Draft, subject to change.
  9299.  
  9300.  
  9301.  
  9302.  
  9303.  
  9304.  2.5 Locale                                                            111
  9305.  
  9306.  
  9307.  
  9308.  
  9309.  
  9310.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9311.  
  9312.  /*      The following is the LC_MESSAGES category grammar */               1
  9313.  
  9314.  lc_messages             : messages_hdr messages_keywords      messages_tlr 2
  9315.                          | messages_hdr 'copy' locale_name EOL messages_tlr 2
  9316.                          ;                                                  2
  9317.  
  9318.  messages_hdr            : 'LC_MESSAGES' EOL                                2
  9319.                          ;                                                  2
  9320.  
  9321.  messages_keywords       : messages_keywords messages_keyword               2
  9322.                          | messages_keyword                                 2
  9323.                          ;                                                  1
  9324.  
  9325.  messages_keyword        : 'yesexpr' '"' EXTENDED_REG_EXP '"' EOL           2
  9326.                          | 'noexpr'  '"' EXTENDED_REG_EXP '"' EOL           2
  9327.                          ;                                                  2
  9328.  
  9329.  messages_tlr            : 'END' 'LC_MESSAGES' EOL                          2
  9330.                          ;                                                  1
  9331.  
  9332.  /*      The following is the LC_MONETARY category grammar */               1
  9333.  
  9334.  lc_monetary             : monetary_hdr monetary_keywords       monetary_tlr2
  9335.                          | monetary_hdr 'copy' locale_name EOL  monetary_tlr2
  9336.                          ;                                                  2
  9337.  
  9338.  monetary_hdr            : 'LC_MONETARY' EOL                                2
  9339.                          ;                                                  2
  9340.  
  9341.  monetary_keywords       : monetary_keywords monetary_keyword               2
  9342.                          | monetary_keyword                                 2
  9343.                          ;                                                  1
  9344.  
  9345.  monetary_keyword        : mon_keyword_string mon_string EOL                1
  9346.                          | mon_keyword_char NUMBER EOL                      2
  9347.                          | mon_keyword_char '-1'   EOL                      2
  9348.                          | mon_keyword_grouping mon_group_list EOL          1
  9349.                          ;                                                  1
  9350.  
  9351.  mon_keyword_string      : 'int_curr_symbol' | 'currency_symbol'            1
  9352.                          | 'mon_decimal_point' | 'mon_thousands_sep'        1
  9353.                          | 'positive_sign' | 'negative_sign'                1
  9354.                          ;                                                  1
  9355.  
  9356.  mon_string              : '"' char_list '"'                                1
  9357.                          | '""'                                             1
  9358.                          ;                                                  1
  9359.  
  9360.  
  9361.  
  9362.  
  9363.                Copyright c 1991 IEEE.  All rights reserved.
  9364.       This is an unapproved IEEE Standards Draft, subject to change.
  9365.  
  9366.  
  9367.  
  9368.  
  9369.  
  9370.  112                                2 Terminology and General Requirements
  9371.  
  9372.  
  9373.  
  9374.  
  9375.  
  9376.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9377.  
  9378.  mon_keyword_char        : 'int_frac_digits' | 'frac_digits'                1
  9379.                          | 'p_cs_precedes' | 'p_sep_by_space'               1
  9380.                          | 'n_cs_precedes' | 'n_sep_by_space'               1
  9381.                          | 'p_sign_posn' | 'n_sign_posn'                    1
  9382.                          ;                                                  1
  9383.                                                                             2
  9384.  
  9385.  mon_keyword_grouping    : 'mon_grouping'                                   1
  9386.                          ;                                                  1
  9387.  
  9388.  mon_group_list          : NUMBER                                           2
  9389.                          | mon_group_list ';' NUMBER                        2
  9390.                          ;                                                  2
  9391.  
  9392.  monetary_tlr            : 'END' 'LC_MONETARY' EOL                          2
  9393.                          ;                                                  2
  9394.  
  9395.  /*      The following is the LC_NUMERIC category grammar */                2
  9396.  
  9397.  lc_numeric              : numeric_hdr numeric_keywords       numeric_tlr   2
  9398.                          | numeric_hdr 'copy' locale_name EOL numeric_tlr   2
  9399.                          ;                                                  2
  9400.  
  9401.  numeric_hdr             : 'LC_NUMERIC' EOL                                 2
  9402.                          ;                                                  2
  9403.  
  9404.  numeric_keywords        : numeric_keywords numeric_keyword                 2
  9405.                          | numeric_keyword                                  2
  9406.                          ;                                                  1
  9407.  
  9408.  numeric_keyword         : num_keyword_string num_string EOL                1
  9409.                          | num_keyword_grouping num_group_list EOL          1
  9410.                          ;                                                  1
  9411.  
  9412.  num_keyword_string      : 'decimal_point'                                  1
  9413.                          | 'thousands_sep'                                  1
  9414.                          ;                                                  1
  9415.  
  9416.  num_string              : '"' char_list '"'                                1
  9417.                          | '""'                                             1
  9418.                          ;                                                  1
  9419.  
  9420.  num_keyword_grouping    : 'num_grouping'                                   1
  9421.                          ;                                                  1
  9422.  
  9423.  num_group_list          : NUMBER                                           2
  9424.                          | num_group_list ';' NUMBER                        2
  9425.                          ;                                                  1
  9426.                                                                             2
  9427.  
  9428.  
  9429.                Copyright c 1991 IEEE.  All rights reserved.
  9430.       This is an unapproved IEEE Standards Draft, subject to change.
  9431.  
  9432.  
  9433.  
  9434.  
  9435.  
  9436.  2.5 Locale                                                            113
  9437.  
  9438.  
  9439.  
  9440.  
  9441.  
  9442.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9443.  
  9444.  numeric_tlr             : 'END' 'LC_NUMERIC' EOL                           2
  9445.                          ;                                                  1
  9446.  
  9447.  /*      The following is the LC_TIME category grammar */                   1
  9448.  
  9449.  lc_time                 : time_hdr time_keywords          time_tlr         2
  9450.                          | time_hdr 'copy' locale_name EOL time_tlr         2
  9451.                          ;                                                  1
  9452.  
  9453.  time_hdr                : 'LC_TIME' EOL                                    2
  9454.                          ;                                                  1
  9455.  
  9456.  time_keywords           : time_keywords time_keyword                       2
  9457.                          | time_keyword                                     2
  9458.                          ;                                                  1
  9459.  
  9460.  time_keyword            : time_keyword_name time_list EOL                  2
  9461.                          | time_keyword_fmt time_string EOL                 1
  9462.                          | time_keyword_opt time_list EOL                   1
  9463.                          ;                                                  1
  9464.  
  9465.  time_keyword_name       : 'abday' | 'day' | 'abmon' | 'mon'                2
  9466.                          ;                                                  1
  9467.  
  9468.  time_keyword_fmt        : 'd_t_fmt' | 'd_fmt' | 't_fmt' | 'am_pm' | 't_fmt_ampm'1
  9469.                          ;                                                  1
  9470.  
  9471.  time_keyword_opt        : 'era' | 'era_year' | 'era_d_fmt' | 'alt_digits'  1
  9472.                          ;                                                  1
  9473.  
  9474.  time_list               : time_list ';' time_string                        2
  9475.                          | time_string                                      2
  9476.                          ;                                                  1
  9477.  
  9478.  time_string             : '"' char_list '"'                                1
  9479.                          ;                                                  1
  9480.  
  9481.  time_tlr                : 'END' 'LC_TIME' EOL                              2
  9482.                          ;                                                  1
  9483.  
  9484.  BEGIN_RATIONALE                                                            1
  9485.  
  9486.  
  9487.  
  9488.  
  9489.  
  9490.  
  9491.  
  9492.  
  9493.  
  9494.  
  9495.                Copyright c 1991 IEEE.  All rights reserved.
  9496.       This is an unapproved IEEE Standards Draft, subject to change.
  9497.  
  9498.  
  9499.  
  9500.  
  9501.  
  9502.  114                                2 Terminology and General Requirements
  9503.  
  9504.  
  9505.  
  9506.  
  9507.  
  9508.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9509.  
  9510.  2.5.4  Locale Definition Example. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  9511.         _P_1_0_0_3._2)
  9512.  
  9513.  The following is an example of a locale definition file that could be
  9514.  used as input to the localedef utility.  It assumes that the utility is
  9515.  executed with the -f option, naming a _c_h_a_r_m_a_p file with (at least) the
  9516.  following content:
  9517.  
  9518.  CHARMAP
  9519.  <space>        \x20
  9520.  <dollar>       \x24
  9521.  <A>            \101
  9522.  <a>            \141
  9523.  <A-acute>      \346
  9524.  <a-acute>      \365
  9525.  <A-grave>      \300                                                        1
  9526.  <a-grave>      \366
  9527.  <b>            \142
  9528.  <C>            \103
  9529.  <c>            \143
  9530.  <c-cedilla>    \347
  9531.  <d>            \x64
  9532.  <H>            \110
  9533.  <h>            \150
  9534.  <eszet>        \xb7
  9535.  <s>            \x73
  9536.  <z>            \x7a
  9537.  END CHARMAP
  9538.  
  9539.  It should not be taken as complete or to represent any actual locale, but
  9540.  only to illustrate the syntax.
  9541.  
  9542.  A further set of examples is offered as part of Annex F.
  9543.  
  9544.  #
  9545.  LC_CTYPE
  9546.  lower   <a>;<b>;<c>;<c-cedilla>;<d>;...;<z>
  9547.  upper   A;B;C;C,;...;Z
  9548.  space   \x20;\x09;\x0a;\x0b;\x0c;\x0d                                      1
  9549.  blank   \040;\011
  9550.  toupper (<a>,<A>);(b,B);(c,C);(c,,C,);(d,D);(z,Z)
  9551.  END LC_CTYPE
  9552.  #
  9553.  LC_COLLATE
  9554.  #
  9555.  # The following example of collation is based on the proposed              1
  9556.  # Canadian standard Z243.4.1-1990, "Canadian Alphanumeric                  1
  9557.  # Ordering Standard For Character sets of CSA Z234.4 Standard".            1
  9558.  # (Other parts of this example locale definition file do not               1
  9559.  
  9560.  
  9561.                Copyright c 1991 IEEE.  All rights reserved.
  9562.       This is an unapproved IEEE Standards Draft, subject to change.
  9563.  
  9564.  
  9565.  
  9566.  
  9567.  
  9568.  2.5 Locale                                                            115
  9569.  
  9570.  
  9571.  
  9572.  
  9573.  
  9574.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9575.  
  9576.  # purport to relate to Canada, or to any other real culture.)              1
  9577.  # The proposed standard defines a 4-weight collation, such that
  9578.  # in the first pass, characters are compared without regard to
  9579.  # case or accents; in second pass, backwards compare without
  9580.  # regard to case; in the third pass, forward compare without
  9581.  # regard to diacriticals.  In the 3 first passes, non-alphabetic           2
  9582.  # characters are ignored; in the fourth pass, only special
  9583.  # characters are considered, such that "The string that has a
  9584.  # special character in the lowest position comes first.  If two
  9585.  # strings have a special character in the same position, the
  9586.  # collation value of the special character determines ordering.
  9587.  #
  9588.  # Only a subset of the character set is used here; mostly to
  9589.  # illustrate the set-up.
  9590.  #
  9591.                                                                             2
  9592.  #
  9593.  collating-symbol <LOW_VALUE>                                               2
  9594.  collating-symbol <LOWER-CASE>
  9595.  collating-symbol <SUBSCRIPT-LOWER>
  9596.  collating-symbol <SUPERSCRIPT-LOWER>
  9597.  collating-symbol <UPPER-CASE>
  9598.  collating-symbol <NO-ACCENT>
  9599.  collating-symbol <PECULIAR>
  9600.  collating-symbol <LIGATURE>
  9601.  collating-symbol <ACUTE>
  9602.  collating-symbol <GRAVE>
  9603.  # Further collating-symbols follow.
  9604.  #
  9605.  # Properly, the standard does not include any multi-character
  9606.  # collating elements; the one below is added for completeness.
  9607.  #
  9608.  collating_element <ch> from <c><h>
  9609.  collating_element <CH> from <C><H>
  9610.  collating_element <Ch> from <C><h>
  9611.  #
  9612.  order_start forward;backward;forward;forward,position
  9613.  #
  9614.  # Collating symbols are specified first in the sequence to allocate
  9615.  # basic collation values to them, lower that than of any character.
  9616.        
  9617.  <LOW_VALUE>                                                            2
  9618.  <LOWER-CASE>
  9619.  <SUBSCRIPT-LOWER>
  9620.  <SUPERSCRIPT-LOWER>
  9621.  <UPPER-CASE>
  9622.  <NO-ACCENT>
  9623.  <PECULIAR>
  9624.  <LIGATURE>
  9625.  
  9626.  
  9627.                Copyright c 1991 IEEE.  All rights reserved.
  9628.       This is an unapproved IEEE Standards Draft, subject to change.
  9629.  
  9630.  
  9631.  
  9632.  
  9633.  
  9634.  116                                2 Terminology and General Requirements
  9635.  
  9636.  
  9637.  
  9638.  
  9639.  
  9640.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9641.  
  9642.  <ACUTE>
  9643.  <GRAVE>
  9644.  <RING-ABOVE>
  9645.  <DIAERESIS>
  9646.  <TILDE>
  9647.  # Further collating symbols are given a basic collating value here.
  9648.  #
  9649.  # Here follows special characters.
  9650.  <space>        IGNORE;IGNORE;IGNORE;<space>
  9651.  # Other special characters follow here.
  9652.  #
  9653.  # Here comes the regular characters.
  9654.  <a>            <a>;<NO-ACCENT>;<LOWER-CASE>;IGNORE
  9655.  <A>            <a>;<NO-ACCENT>;<UPPER-CASE>;IGNORE
  9656.  <a-acute>      <a>;<ACUTE>;<LOWER-CASE>;IGNORE
  9657.  <A-acute>      <a>;<ACUTE>;<UPPER-CASE>;IGNORE
  9658.  <a-grave>      <a>;<GRAVE>;<LOWER-CASE>;IGNORE
  9659.  <A-grave>      <a>;<GRAVE>;<UPPER-CASE>;IGNORE
  9660.  <ae>           <a><e>;<LIGATURE><LIGATURE>;<LOWER-CASE><LOWER-CASE>;IGNORE
  9661.  <AE>           <a><e>;<LIGATURE><LIGATURE>;<UPPER-CASE><UPPER-CASE>;IGNORE
  9662.  <b>            <b>;<NO-ACCENT>;<LOWER-CASE>;IGNORE
  9663.  <B>            <b>;<NO-ACCENT>;<UPPER-CASE>;IGNORE
  9664.  <c>            <c>;<NO-ACCENT>;<LOWER-CASE>;IGNORE
  9665.  <C>            <c>;<NO-ACCENT>;<UPPER-CASE>;IGNORE
  9666.  <ch>           <ch>;<NO-ACCENT>;<LOWER-CASE>;IGNORE
  9667.  <Ch>           <ch>;<NO-ACCENT>;<PECULIAR>;IGNORE
  9668.  <CH>           <ch>;<NO-ACCENT>;<UPPER-CASE>;IGNORE
  9669.  #
  9670.  # As an example, the strings "Bach" and "bach" could be encoded (for
  9671.  # compare purposes) as:
  9672.  # "Bach"  <b>;<a>;<ch>;<LOW_VALUE>;<NO_ACCENT>;<NO_ACCENT>;\               2
  9673.  #              <NO_ACCENT>;<LOW_VALUE>;<UPPER>;<LOWER>;<LOWER>;<NULL>      2
  9674.  # "bach"  <b>;<a>;<ch>;<LOW_VALUE>;<NO_ACCENT>;<NO_ACCENT>;\               2
  9675.  #              <NO_ACCENT>;<LOW_VALUE>;<LOWER>;<LOWER>;<LOWER>;<NULL>      2
  9676.  #
  9677.  # The two strings are equal in pass 1 and 2, but differ in pass 3.
  9678.  #
  9679.  # Further characters follow.
  9680.  #
  9681.  UNDEFINED      IGNORE;IGNORE;IGNORE;IGNORE
  9682.  #
  9683.  order_end
  9684.  #
  9685.  END LC_COLLATE
  9686.  #
  9687.  LC_MONETARY
  9688.  int_curr_symbol         "USD "
  9689.  currency_symbol         "$"
  9690.  mon_decimal_point       "."
  9691.  
  9692.  
  9693.                Copyright c 1991 IEEE.  All rights reserved.
  9694.       This is an unapproved IEEE Standards Draft, subject to change.
  9695.  
  9696.  
  9697.  
  9698.  
  9699.  
  9700.  2.5 Locale                                                            117
  9701.  
  9702.  
  9703.  
  9704.  
  9705.  
  9706.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9707.  
  9708.  mon_grouping            3;0
  9709.  positive_sign           ""
  9710.  negative_sign           "-"
  9711.  p_cs_precedes           1
  9712.  n_sign_posn             0
  9713.  END LC_MONETARY
  9714.  #
  9715.  LC_NUMERIC
  9716.  copy "US_en.ASCII"                                                         1
  9717.  END LC_NUMERIC
  9718.  #
  9719.  LC_TIME
  9720.  abday       "Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"
  9721.  #
  9722.  day         "Sunday";"Monday";"Tuesday";"Wednesday";\
  9723.              "Thursday";"Friday";"Saturday"
  9724.  #
  9725.  abmon       "Jan";"Feb";"Mar";"Apr";"May";"Jun";\
  9726.              "Jul";"Aug";"Sep";"Oct";"Nov";"Dec"
  9727.  #
  9728.  mon         "January";"February";"March";"April";\
  9729.              "May";"June";"July";"August";"September";\
  9730.              "October";"November";"December"
  9731.  #
  9732.  d_t_fmt     "%a %b %d %T %Z %Y\n"
  9733.  END LC_TIME
  9734.  #
  9735.  LC_MESSAGES
  9736.  yesexpr     "^([yY][[:alpha:]]*)|(OK)"                                     1
  9737.  #
  9738.  noexpr      "^[nN][[:alpha:]]*"                                            1
  9739.  END LC_MESSAGES
  9740.  
  9741.  END_RATIONALE
  9742.  
  9743.  
  9744.  
  9745.  
  9746.  
  9747.  
  9748.  
  9749.  
  9750.  
  9751.  
  9752.  
  9753.  
  9754.  
  9755.  
  9756.  
  9757.  
  9758.  
  9759.                Copyright c 1991 IEEE.  All rights reserved.
  9760.       This is an unapproved IEEE Standards Draft, subject to change.
  9761.  
  9762.  
  9763.  
  9764.  
  9765.  
  9766.  118                                2 Terminology and General Requirements
  9767.  
  9768.  
  9769.  
  9770.  
  9771.  
  9772.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9773.  
  9774.  2.6  Environment Variables
  9775.  
  9776.  Environment variables defined in this clause affect the operation of
  9777.  multiple utilities and applications.  There are other environment
  9778.  variables that are of interest only to specific utilities.  Environment
  9779.  variables that apply to a single utility only are defined as part of the
  9780.  utility description.  See the Environment Variables subclause of the
  9781.  utility descriptions for information on environment variable usage.
  9782.  
  9783.  The value of an environment variable is a string of characters, as
  9784.  described in 2.7 in POSIX.1 {8}.
  9785.  
  9786.  Environment variable names used by the standard utilities shall consist
  9787.  solely of uppercase letters, digits, and the _ (underscore) from the
  9788.  characters defined in 2.4.  The namespace of environment variable names
  9789.  containing lowercase letters shall be reserved for applications.
  9790.  Applications can define any environment variables with names from this
  9791.  namespace without modifying the behavior of the standard utilities.
  9792.  
  9793.  If the following variables are present in the environment during the
  9794.  execution of an application or utility, they are given the meaning
  9795.  described below.  They may be put into the environment, or changed, by
  9796.  either the implementation or the user.  If they are defined in the
  9797.  utility's environment, the standard utilities assume they have the
  9798.  specified meaning.  Conforming applications shall not set these
  9799.  environment variables to have meanings other than as described.  See 7.2
  9800.  and 3.12 for methods of accessing these variables.
  9801.  
  9802.     HOME             A pathname of the user's home directory.
  9803.  
  9804.     LANG             This variable shall determine the locale category for  1
  9805.                      any category not specifically selected via a variable  1
  9806.                      starting with LC_.  LANG and the LC_ variables can be  1
  9807.                      used by applications to determine the language for
  9808.                      messages and instructions, collating sequences, date
  9809.                      formats, etc.  Additional semantics of this variable,
  9810.                      if any, are implementation defined.
  9811.  
  9812.     LC_ALL           This variable shall override the value of the LANG
  9813.                      variable and the value of any of the other variables
  9814.                      starting with LC_.
  9815.  
  9816.     LC_COLLATE       This variable shall determine the locale category for
  9817.                      character collation information within bracketed
  9818.                      regular expressions and for sorting.  This
  9819.                      environment variable determines the behavior of
  9820.                      ranges, equivalence classes, and multicharacter
  9821.                      collating elements.  Additional semantics of this
  9822.                      variable, if any, are implementation defined.
  9823.  
  9824.  
  9825.                Copyright c 1991 IEEE.  All rights reserved.
  9826.       This is an unapproved IEEE Standards Draft, subject to change.
  9827.  
  9828.  
  9829.  
  9830.  
  9831.  
  9832.  2.6 Environment Variables                                             119
  9833.  
  9834.  
  9835.  
  9836.  
  9837.  
  9838.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9839.  
  9840.     LC_CTYPE         This variable shall determine the locale category for
  9841.                      character handling functions.  This environment
  9842.                      variable shall determine the interpretation of
  9843.                      sequences of bytes of text data as characters (e.g.,
  9844.                      single- versus multibyte characters), the
  9845.                      classification of characters (e.g., alpha, digit,
  9846.                      graph), and the behavior of character classes.
  9847.                      Additional semantics of this variable, if any, are
  9848.                      implementation defined.
  9849.  
  9850.     LC_MESSAGES      This variable shall determine the locale category for
  9851.                      processing affirmative and negative responses and the
  9852.                      language and cultural conventions in which messages
  9853.                      should be written.  Additional semantics of this
  9854.                      variable, if any, are implementation defined.  The
  9855.                      language and cultural conventions of diagnostic and
  9856.                      informative messages whose format is unspecified by
  9857.                      this standard should be affected by the setting of
  9858.                      LC_MESSAGES.
  9859.  
  9860.     LC_MONETARY      This variable shall determine the locale category for
  9861.                      monetary-related numeric formatting information.
  9862.                      Additional semantics of this variable, if any, are
  9863.                      implementation defined.
  9864.  
  9865.     LC_NUMERIC       This variable shall determine the locale category for
  9866.                      numeric formatting (for example, thousands separator
  9867.                      and radix character) information.  Additional
  9868.                      semantics of this variable, if any, are
  9869.                      implementation defined.
  9870.  
  9871.     LC_TIME          This variable shall determine the locale category for
  9872.                      date and time formatting information.  Additional
  9873.                      semantics of this variable, if any, are
  9874.                      implementation defined.
  9875.  
  9876.     LOGNAME          The user's login name.
  9877.  
  9878.     PATH             The sequence of path prefixes that certain functions
  9879.                      and utilities apply in searching for an executable
  9880.                      file known only by a filename.  The prefixes shall be
  9881.                      separated by a colon (:).  When a nonzero-length
  9882.                      prefix is applied to this filename, a slash shall be
  9883.                      inserted between the prefix and the filename.  A
  9884.                      zero-length prefix is an obsolescent feature that
  9885.                      indicates the current working directory.  It appears
  9886.                      as two adjacent colons (::), as an initial colon
  9887.                      preceding the rest of the list, or as a trailing
  9888.                      colon following the rest of the list.  A Strictly
  9889.  
  9890.  
  9891.                Copyright c 1991 IEEE.  All rights reserved.
  9892.       This is an unapproved IEEE Standards Draft, subject to change.
  9893.  
  9894.  
  9895.  
  9896.  
  9897.  
  9898.  120                                2 Terminology and General Requirements
  9899.  
  9900.  
  9901.  
  9902.  
  9903.  
  9904.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  9905.  
  9906.                      Conforming POSIX.2 Application shall use an actual
  9907.                      pathname (such as '.') to represent the current
  9908.                      working directory in PATH.  The list shall be
  9909.                      searched from beginning to end, applying the filename
  9910.                      to each prefix, until an executable file with the
  9911.                      specified name and appropriate execution permissions
  9912.                      is found.  If the pathname being sought contains a
  9913.                      slash, the search through the path prefixes shall not
  9914.                      be performed.  If the pathname begins with a slash,
  9915.                      the specified path shall be resolved as described in
  9916.                      2.2.2.104.  If PATH is unset or is set to null, the
  9917.                      path search is implementation-defined.
  9918.  
  9919.     SHELL            A pathname of the user's preferred command language
  9920.                      interpreter.  If this interpreter does not conform to
  9921.                      the shell command language in Section 3, utilities
  9922.                      may behave differently than described in this
  9923.                      standard.
  9924.  
  9925.     TMPDIR           A pathname of a directory made available for programs
  9926.                      that need a place to create temporary files.
  9927.  
  9928.     TERM             The terminal type for which output is to be prepared.
  9929.                      This information is used by utilities and application
  9930.                      programs wishing to exploit special capabilities
  9931.                      specific to a terminal.  The format and allowable
  9932.                      values of this environment variable are unspecified.
  9933.  
  9934.     TZ               Time-zone information.  The format is described in
  9935.                      POSIX.1 {8} 8.1.1.
  9936.  
  9937.  The environment variables LANG, LC_ALL, LC_COLLATE, LC_CTYPE,
  9938.  LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME (LC_*) provide for the
  9939.  support of internationalized applications.  The standard utilities shall
  9940.  make use of these environment variables as described in this clause and
  9941.  the individual Environment Variables subclauses for the utilities.  If
  9942.  these variables specify locale categories that are not based upon the
  9943.  same underlying code set, the results are unspecified.
  9944.  
  9945.  For utilities used in internationalized applications, if the LC_ALL is
  9946.  not set in the environment or is set to the empty string, and if any of
  9947.  LC_* variables is not set in the environment or is set to the empty
  9948.  string, the operational behavior of the utility for the corresponding
  9949.  locale category shall be determined by the setting of the LANG
  9950.  environment variable.  If the LANG environment variable is not set or is
  9951.  set to the empty string, the implementation-defined default locale shall
  9952.  be used.
  9953.  
  9954.  
  9955.  
  9956.  
  9957.                Copyright c 1991 IEEE.  All rights reserved.
  9958.       This is an unapproved IEEE Standards Draft, subject to change.
  9959.  
  9960.  
  9961.  
  9962.  
  9963.  
  9964.  2.6 Environment Variables                                             121
  9965.  
  9966.  
  9967.  
  9968.  
  9969.  
  9970.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  9971.  
  9972.  If LANG (or any of the LC_* environment variables) contains the value
  9973.  "C", or the value "POSIX", the POSIX Locale shall be selected and the
  9974.  standard utilities shall behave in accordance with the rules in the 2.5.1
  9975.  for the associated category.
  9976.  
  9977.  If LANG (or any of the LC_* environment variables) begins with a slash,
  9978.  it shall be interpreted as the pathname of a file that was created in the
  9979.  output format used by the localedef utility; see 4.35.6.3.  Referencing
  9980.  such a pathname shall result in that locale being used for the category
  9981.  indicated.
  9982.  
  9983.  If LANG (or any of the LC_* environment variables) contains one of a set
  9984.  of implementation-defined values, the standard utilities shall behave in
  9985.  accordance with the rules in a corresponding implementation-defined
  9986.  locale description for the associated category.
  9987.  
  9988.  If LANG (or any of the LC_* environment variables) contains a value that
  9989.  the implementation does not recognize, the behavior is unspecified.
  9990.  
  9991.  Additional criteria for determining a valid locale name are
  9992.  implementation defined.
  9993.  
  9994.  BEGIN_RATIONALE
  9995.  
  9996.  
  9997.  2.6.1  Environment Variables Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  9998.         _P_1_0_0_3._2)
  9999.  
  10000.  The standard is worded so that the specified variables _m_a_y be provided to
  10001.  the application.  There is no way that the implementation can guarantee
  10002.  that a utility will ever see an environment variable, as a parent process
  10003.  can change the environment for its children.  The env -i command in this
  10004.  standard and the POSIX.1 {8} _e_x_e_c family both offer ways to remove any of
  10005.  these variables from the environment.
  10006.  
  10007.  The language about locale implies that any utilities written in Standard
  10008.  C and conforming to POSIX.2 must issue the following call:
  10009.  
  10010.        setlocale(LC_ALL, "")
  10011.  
  10012.  If this were omitted, the C Standard {7} specifies that the C Locale
  10013.  would be used.
  10014.  
  10015.  If any of the environment variables is invalid, it makes sense to default
  10016.  to an implementation-defined, consistent locale environment.  It is more
  10017.  confusing for a user to have partial settings occur in case of a mistake.
  10018.  All utilities would then behave in one language/cultural environment.
  10019.  Furthermore, it provides a way of forcing the whole environment to be the
  10020.  implementation-defined default.  Disastrous results could occur if a
  10021.  
  10022.  
  10023.                Copyright c 1991 IEEE.  All rights reserved.
  10024.       This is an unapproved IEEE Standards Draft, subject to change.
  10025.  
  10026.  
  10027.  
  10028.  
  10029.  
  10030.  122                                2 Terminology and General Requirements
  10031.  
  10032.  
  10033.  
  10034.  
  10035.  
  10036.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10037.  
  10038.  pipeline of utilities partially use the environment variables in
  10039.  different ways.  In this case, it would be appropriate for utilities that
  10040.  use LANG and related variables to exit with an error if any of the
  10041.  variables are invalid.  For example, users typing individual commands at
  10042.  a terminal might want date to work if LC_MONETARY is invalid as long as
  10043.  LC_TIME is valid.  Since these are conflicting reasonable alternatives,
  10044.  POSIX.2 leaves the results unspecified if the locale environment
  10045.  variables would not produce a complete locale matching the user's
  10046.  specification.
  10047.  
  10048.  The locale settings of individual categories cannot be truly independent
  10049.  and still guarantee correct results.  For example, when collating two
  10050.  strings, characters must first be extracted from each string (governed by
  10051.  LC_CTYPE) before being mapped to collating elements (governed by
  10052.  LC_COLLATE) for comparison.  That is, if LC_CTYPE is causing parsing
  10053.  according to the rules of a large, multibyte code set (potentially
  10054.  returning 20000 or more distinct character code set values), but
  10055.  LC_COLLATE is set to handle only an 8-bit code set with 256 distinct
  10056.  characters, meaningful results are obviously impossible.
  10057.  
  10058.  The LC_MESSAGES variable affects the language of messages generated by
  10059.  the standard utilities.  This standard does not provide a means whereby
  10060.  applications can easily be written to perform similar feats.  Future
  10061.  versions of POSIX.1 {8} and POSIX.2 are expected to provide both
  10062.  functions and utilities to accomplish multilanguage messaging (using
  10063.  message catalogs), but such facilities were not ready for standardization
  10064.  at the time the initial versions of the standards were developed.
  10065.  
  10066.  This clause is not a full list of all environment variables, but only
  10067.  those of importance to multiple utilities.  Nevertheless, to satisfy some
  10068.  members of the balloting group, here is a list of the other environment
  10069.  variable symbols mentioned in this standard:
  10070.  
  10071.                Variable   Utility        Variable    Utility
  10072.                ________   _______        _________   _______
  10073.                CDPATH     cd             MAKEFLAGS   make
  10074.                COLUMNS    ls             OPTARG      getopts
  10075.                DEAD       mailx          OPTIND      getopts
  10076.                IFS        sh             PRINTER     lp                     1
  10077.                LPDEST     lp             PS1         sh
  10078.                MAIL       sh             PS2         sh
  10079.                MAILRC     mailx
  10080.  
  10081.  The description of PATH is similar to that in POSIX.1 {8}, except:
  10082.  
  10083.      - The behavior of a null prefix is marked obsolescent in favor of
  10084.        using a real pathname.  This was done at the behest of some members
  10085.        of the balloting group, who apparently felt it offered a more
  10086.        secure environment, where the current directory would not be
  10087.        selected unintentionally.
  10088.  
  10089.                Copyright c 1991 IEEE.  All rights reserved.
  10090.       This is an unapproved IEEE Standards Draft, subject to change.
  10091.  
  10092.  
  10093.  
  10094.  
  10095.  
  10096.  2.6 Environment Variables                                             123
  10097.  
  10098.  
  10099.  
  10100.  
  10101.  
  10102.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10103.  
  10104.      - The POSIX.1 {8} _e_x_e_c description requires an implementation-defined
  10105.        path search when PATH is ``not present.''  POSIX.2 spells out that
  10106.        this means ``unset or set to null.''  Many implementations
  10107.        historically have used a default value of /bin and /usr/bin.
  10108.        POSIX.2 does not mandate that this default path be identical to
  10109.        that retrieved from getconf _CS_PATH because it is likely that a
  10110.        transition to POSIX.2 conformance will see the newly-standardized
  10111.        utilities in another directory that needs to be isolated from some
  10112.        historical applications.
  10113.  
  10114.      - The POSIX.1 {8} PATH description is ambiguous about whether an
  10115.        ``executable file'' means one that has the appropriate permissions
  10116.        for the searching process to execute it.  One reading would say
  10117.        that a file with any of the execution bits set on would satisfy the
  10118.        search and that an [EACCES] could be returned at that point.  This
  10119.        is not the way historical systems work and POSIX.2 has clarified it
  10120.        to mean that the path search will continue until it finds the name
  10121.        with the execute permissions that would allow the process to
  10122.        execute it.  (The case of the [ENOEXEC] error is handled in the
  10123.        text of 3.9.1.1.)
  10124.  
  10125.  The terminology ``beginning to end'' is used in PATH to avoid the
  10126.  noninternationalized ``left to right.''  There is no way to have a colon
  10127.  character embedded within a pathname that is part of the PATH variable
  10128.  string.  Colon is not a member of the portable filename character set, so
  10129.  this should not be a problem.  A portable application can retrieve a
  10130.  default PATH value (that will allow access to all the standard utilities)
  10131.  from the system using the command:
  10132.  
  10133.        getconf _CS_PATH
  10134.  
  10135.  See the rationale with command for an example of using this.
  10136.  
  10137.  The SHELL variable names the user's preferred shell; it is a guide to
  10138.  applications.  There is no direct requirement that that shell conform to
  10139.  this standard--that decision should rest with the user.  It is the
  10140.  intention of the developers of this standard that alternative shells be
  10141.  permitted, if the user chooses to develop or acquire one.  An operating
  10142.  system that builds its shell into the ``kernel'' in such a manner that
  10143.  alternative shells would be impossible does not conform to the spirit of
  10144.  the standard.
  10145.  
  10146.  The following environment variables are not currently used by the
  10147.  standard utilities (although they may be by future UPE utilities).
  10148.  Implementations should reserve the names for the following purposes:
  10149.  
  10150.     EDITOR      The name of the user's preferred text file editor.  The
  10151.                 value of this variable is the name of a utility:  either a
  10152.                 pathname containing a slash, or a filename to be located
  10153.  
  10154.  
  10155.                Copyright c 1991 IEEE.  All rights reserved.
  10156.       This is an unapproved IEEE Standards Draft, subject to change.
  10157.  
  10158.  
  10159.  
  10160.  
  10161.  
  10162.  124                                2 Terminology and General Requirements
  10163.  
  10164.  
  10165.  
  10166.  
  10167.  
  10168.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10169.  
  10170.                 using the PATH environment variable.
  10171.  
  10172.     VISUAL      The name of the user's preferred ``visual,'' or full-
  10173.                 screen, text file editor.  The value of this variable is
  10174.                 the name of a utility:  either a pathname containing a
  10175.                 slash, or a filename to be located using the PATH
  10176.                 environment variable.
  10177.  
  10178.  The decision to restrict conforming systems to the use of digits,
  10179.  uppercase letters, and underscores for environment variable names allows
  10180.  applications to use lowercase letters in their environment variable names
  10181.  without conflicting with any conforming system.
  10182.  
  10183.  PROCLANG was added to an earlier draft for internationalized
  10184.  applications, but was removed from the standard because the working group
  10185.  determined that it was not of use.
  10186.  
  10187.  USER was removed from an earlier draft because it was an unreasonable
  10188.  duplication of LOGNAME.
  10189.  
  10190.  END_RATIONALE
  10191.  
  10192.  
  10193.  
  10194.  
  10195.  
  10196.  
  10197.  
  10198.  
  10199.  
  10200.  
  10201.  
  10202.  
  10203.  
  10204.  
  10205.  
  10206.  
  10207.  
  10208.  
  10209.  
  10210.  
  10211.  
  10212.  
  10213.  
  10214.  
  10215.  
  10216.  
  10217.  
  10218.  
  10219.  
  10220.  
  10221.                Copyright c 1991 IEEE.  All rights reserved.
  10222.       This is an unapproved IEEE Standards Draft, subject to change.
  10223.  
  10224.  
  10225.  
  10226.  
  10227.  
  10228.  2.6 Environment Variables                                             125
  10229.  
  10230.  
  10231.  
  10232.  
  10233.  
  10234.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10235.  
  10236.  2.7  Required Files
  10237.  
  10238.  The following directories shall exist on conforming systems and shall be
  10239.  used as described.  Strictly Conforming POSIX.2 Applications shall not
  10240.  assume the ability to create files in any of these directories.
  10241.  
  10242.     /           The root directory.
  10243.  
  10244.     /dev        Contains /dev/null and /dev/tty, described below.
  10245.  
  10246.  The following directory shall exist on conforming systems and shall be
  10247.  used as described.
  10248.  
  10249.     /tmp        A directory made available for programs that need a place
  10250.                 to create temporary files.  Applications shall be allowed
  10251.                 to create files in this directory, but shall not assume
  10252.                 that such files are preserved between invocations of the
  10253.                 application.
  10254.  
  10255.  The following files shall exist on conforming systems and shall be both
  10256.  readable and writable.
  10257.  
  10258.     /dev/null   An infinite data source/sink.  Data written to /dev/null
  10259.                 is discarded.  Reads from /dev/null always return end-of-
  10260.                 file (EOF).
  10261.  
  10262.     /dev/tty    In each process, a synonym for the controlling terminal
  10263.                 associated with the process group of that process, if any.
  10264.                 It is useful for programs or shell procedures that wish to
  10265.                 be sure of writing messages to or reading data from the
  10266.                 terminal no matter how output has been redirected.
  10267.  
  10268.  BEGIN_RATIONALE
  10269.  
  10270.  
  10271.  2.7.1  Required Files Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  10272.         _P_1_0_0_3._2)
  10273.  
  10274.  A description of the historical /usr/tmp was omitted, removing any
  10275.  concept of differences in emphasis between the / and /usr versions.  The
  10276.  descriptions of /bin, /usr/bin, /lib, and /usr/lib were omitted because
  10277.  they are not useful for applications.  In an early draft, a distinction
  10278.  was made between _s_y_s_t_e_m and _a_p_p_l_i_c_a_t_i_o_n directory usage, but this was not
  10279.  found to be useful.
  10280.  
  10281.  In Draft 8, /, /dev, /local, /usr/local, and /usr/man were removed.  The
  10282.  directories / and /dev were restored in Draft 9.  It was pointed out by
  10283.  several balloters that the notion of a hierarchical directory structure
  10284.  is key to other information presented in later sections of the standard.
  10285.  
  10286.  
  10287.                Copyright c 1991 IEEE.  All rights reserved.
  10288.       This is an unapproved IEEE Standards Draft, subject to change.
  10289.  
  10290.  
  10291.  
  10292.  
  10293.  
  10294.  126                                2 Terminology and General Requirements
  10295.  
  10296.  
  10297.  
  10298.  
  10299.  
  10300.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10301.  
  10302.  (Previously, some had argued that special devices and temporary files
  10303.  could conceivably be handled without a directory structure on some
  10304.  implementations.  For example, the system could treat the characters
  10305.  ``/tmp'' as a special token that would store files using some non-POSIX
  10306.  file system structure.  This notion was rejected by the working group,
  10307.  which requires that all the files in this clause be implemented via POSIX
  10308.  file systems.)
  10309.  
  10310.  The /tmp directory is retained in the standard to accommodate historical
  10311.  applications that assume its availability.  Future implementations are
  10312.  encouraged to provide suitable directory names in TMPDIR and future
  10313.  applications are encouraged to use the contents of TMPDIR for creating
  10314.  temporary files.
  10315.  
  10316.  The standard files /dev/null and /dev/tty are required to be both
  10317.  readable and writable to allow applications to have the intended
  10318.  historical access to these files.
  10319.  
  10320.  END_RATIONALE
  10321.  
  10322.  
  10323.  
  10324.  
  10325.  
  10326.  
  10327.  
  10328.  
  10329.  
  10330.  
  10331.  
  10332.  
  10333.  
  10334.  
  10335.  
  10336.  
  10337.  
  10338.  
  10339.  
  10340.  
  10341.  
  10342.  
  10343.  
  10344.  
  10345.  
  10346.  
  10347.  
  10348.  
  10349.  
  10350.  
  10351.  
  10352.  
  10353.                Copyright c 1991 IEEE.  All rights reserved.
  10354.       This is an unapproved IEEE Standards Draft, subject to change.
  10355.  
  10356.  
  10357.  
  10358.  
  10359.  
  10360.  2.7 Required Files                                                    127
  10361.  
  10362.  
  10363.  
  10364.  
  10365.  
  10366.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10367.  
  10368.  2.8  Regular Expression Notation
  10369.  
  10370.  _E_d_i_t_o_r'_s _N_o_t_e:  _T_h_e _e_n_t_i_r_e _r_a_t_i_o_n_a_l_e _f_o_r _t_h_i_s _c_l_a_u_s_e _a_p_p_e_a_r_s _a_t _t_h_e _e_n_d
  10371.  _o_f _t_h_e _c_l_a_u_s_e.
  10372.  
  10373.  _R_e_g_u_l_a_r _E_x_p_r_e_s_s_i_o_n_s (REs) provide a mechanism to select specific strings
  10374.  from a set of character strings.
  10375.  
  10376.  Regular expressions are a context-independent syntax that can represent a
  10377.  wide variety of character sets and character set orderings, where these
  10378.  character sets are interpreted according to the current locale.  While
  10379.  many regular expressions can be interpreted differently depending on the
  10380.  current locale, many features, such as character class expressions,
  10381.  provide for contextual invariance across locales.
  10382.  
  10383.  The Basic Regular Expression (BRE) notation and construction rules in
  10384.  2.8.3 shall apply to most utilities supporting regular expressions.  Some
  10385.  utilities, instead, support the Extended Regular Expressions (ERE)
  10386.  described in 2.8.4; any exceptions for both cases are noted in the
  10387.  descriptions of the specific utilities using regular expressions.  Both
  10388.  BREs and EREs are supported by the Regular Expression Matching interface
  10389.  in 7.3.
  10390.  
  10391.  
  10392.  2.8.1  Regular Expression Definitions
  10393.  
  10394.  For the purposes of this clause, the following definitions apply.
  10395.  
  10396.  
  10397.  2.8.1.1  entire regular expression:  The concatenated set of one or more
  10398.  BREs or EREs that make up the pattern specified for string selection.
  10399.  
  10400.  2.8.1.2  matched:  A sequence of zero or more characters is said to be
  10401.  matched by a BRE or ERE when the characters in the sequence corresponds
  10402.  to a sequence of characters defined by the pattern.
  10403.  
  10404.  Matching shall be based on the bit pattern used for encoding the           1
  10405.  character, not on the graphic representation of the character.             1
  10406.  
  10407.  The search for a matching sequence shall start at the beginning of a
  10408.  string and stop when the first sequence matching the expression is found,
  10409.  where ``first'' is defined to mean ``begins earliest in the string.''  If
  10410.  the pattern permits a variable number of matching characters and thus
  10411.  there is more than one such sequence starting at that point, the longest   1
  10412.  such sequence shall be matched.  For example:  the BRE bb* matches the     1
  10413.  second through fourth characters of abbbc, and the ERE                     1
  10414.  (wee|week)(knights|night) matches all ten characters of weeknights.        1
  10415.  
  10416.  
  10417.  
  10418.  
  10419.                Copyright c 1991 IEEE.  All rights reserved.
  10420.       This is an unapproved IEEE Standards Draft, subject to change.
  10421.  
  10422.  
  10423.  
  10424.  
  10425.  
  10426.  128                                2 Terminology and General Requirements
  10427.  
  10428.  
  10429.  
  10430.  
  10431.  
  10432.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10433.  
  10434.  Consistent with the whole match being the longest of the leftmost          1
  10435.  matches, each subpattern, from left to right, shall match the longest      1
  10436.  possible string.  For this purpose, a null string shall be considered to   2
  10437.  be longer than no match at all.  For example, matching the BRE \(.*\).*    2
  10438.  against abcdef, the subexpression (\1) is abcdef, and matching the BRE     2
  10439.  \(a*\)* against bc, the subexpression (\1) is the null string.             2
  10440.  
  10441.  When a multicharacter collating element in a bracket expression (see       1
  10442.  2.8.3.2) is involved, the longest sequence shall be measured in            1
  10443.  characters consumed from the string to be matched; i.e., the collating     1
  10444.  element counts not as one element, but as the number of characters it      1
  10445.  matches.                                                                   1
  10446.  
  10447.  
  10448.  2.8.1.3  BRE [ERE] matching a single character:  A BRE or ERE that
  10449.  matches either a single character or a single collating element.
  10450.  
  10451.  Only a BRE or ERE of this type that includes a bracket expression (see     1
  10452.  2.8.3.2) can match a collating element.                                    1
  10453.  
  10454.  2.8.1.4  BRE [ERE] matching multiple characters:  A BRE or ERE that
  10455.  matches a concatenation of single characters or collating elements.
  10456.  
  10457.  Such a BRE or ERE is made up from a _B_R_E (_E_R_E) _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e _c_h_a_r_a_c_t_e_r
  10458.  and _B_R_E (_E_R_E) _s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_rs.                                          1
  10459.  
  10460.  
  10461.  2.8.2  Regular Expression General Requirements
  10462.  
  10463.  The requirements in this subclause shall apply to both basic and extended
  10464.  regular expressions.
  10465.  
  10466.  The use of regular expressions is generally associated with text
  10467.  processing; i.e., REs (BREs and EREs) operate on text strings; i.e., zero
  10468.  or more characters followed by an end-of-string delimiter (typically
  10469.  NUL).  Some utilities employing regular expressions limit the processing
  10470.  to lines; i.e., zero or more characters followed by a <newline>.  In the
  10471.  regular expression processing described in this standard, the <newline>
  10472.  character is regarded as an ordinary character.  This standard specifies   1
  10473.  within the individual descriptions of those standard utilities employing   1
  10474.  regular expressions whether they permit matching of <newline>s; if not     1
  10475.  stated otherwise, the use of literal <newline>s or any escape sequence     1
  10476.  equivalent produces undefined results.                                     1
  10477.  
  10478.  The interfaces specified in this standard do not permit the inclusion of
  10479.  a NUL character in an RE or in the string to be matched.  If during the
  10480.  operation of a standard utility a NUL is included in the text designated
  10481.  to be matched, that NUL may designate the end of the text string for the   1
  10482.  purposes of matching.                                                      1
  10483.  
  10484.  
  10485.                Copyright c 1991 IEEE.  All rights reserved.
  10486.       This is an unapproved IEEE Standards Draft, subject to change.
  10487.  
  10488.  
  10489.  
  10490.  
  10491.  
  10492.  2.8 Regular Expression Notation                                       129
  10493.  
  10494.  
  10495.  
  10496.  
  10497.  
  10498.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10499.  
  10500.  When a standard utility or function that uses regular expressions
  10501.  specifies that pattern matching shall be performed without regard to the
  10502.  case (upper- or lower-) of either data or patterns, then when each
  10503.  character in the string is matched against the pattern, not only the
  10504.  character, but also its case counterpart (if any), shall be matched.
  10505.  
  10506.  The implementation shall support any regular expression that does not
  10507.  exceed 256 bytes in length.
  10508.  
  10509.  This clause uses the term ``invalid'' for certain constructs or            1
  10510.  conditions.  Invalid REs shall cause the utility or function using the RE  1
  10511.  to generate an error condition.  When ``invalid'' is not used, violations  1
  10512.  of the specified syntax or semantics for REs produce undefined results:    1
  10513.  this may entail an error, enabling an extended syntax for that RE, or      1
  10514.  using the construct in error as literal characters to be matched.          1
  10515.  
  10516.  
  10517.  2.8.3  Basic Regular Expressions
  10518.  
  10519.  
  10520.  2.8.3.1  BREs Matching a Single Character or Collating Element
  10521.  
  10522.  A BRE ordinary character, a special character preceded by a backslash, or
  10523.  a period shall match a single character.  A bracket expression shall
  10524.  match a single character or a single collating element.
  10525.  
  10526.  2.8.3.1.1  BRE Ordinary Characters
  10527.  
  10528.  An ordinary character is a BRE that matches itself:  any character in the
  10529.  supported character set, except for the BRE special characters listed in
  10530.  2.8.3.1.2.
  10531.  
  10532.  The interpretation of an ordinary character preceded by a backslash (\)
  10533.  is undefined, except for:
  10534.  
  10535.      (1)  The characters ), (, {, and }.
  10536.  
  10537.      (2)  The digits 1 through 9 (see 2.8.3.3).
  10538.  
  10539.      (3)  A character inside a bracket expression.
  10540.  
  10541.  2.8.3.1.2  BRE Special Characters
  10542.  
  10543.  A _B_R_E _s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r has special properties in certain contexts.        1
  10544.  Outside of those contexts, or when preceded by a backslash, such a         1
  10545.  character shall be a BRE that matches the special character itself.  The   1
  10546.  BRE special characters and the contexts in which they have their special
  10547.  meaning are:
  10548.  
  10549.  
  10550.  
  10551.                Copyright c 1991 IEEE.  All rights reserved.
  10552.       This is an unapproved IEEE Standards Draft, subject to change.
  10553.  
  10554.  
  10555.  
  10556.  
  10557.  
  10558.  130                                2 Terminology and General Requirements
  10559.  
  10560.  
  10561.  
  10562.  
  10563.  
  10564.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10565.  
  10566.     . [ \    The period, left-bracket, and backslash shall be special
  10567.              except when used in a bracket expression (see 2.8.3.2).  An
  10568.              expression containing a [ that is not preceded by a backslash
  10569.              and is not part of a bracket expression produces undefined     1
  10570.              results.                                                       1
  10571.  
  10572.     *        The asterisk is special except when used
  10573.  
  10574.               - In a bracket expression,                                    1
  10575.  
  10576.               - As the first character of an entire BRE (after an initial   1
  10577.                 ^, if any), or                                              1
  10578.  
  10579.               - As the first character of a subexpression (after an         1
  10580.                 initial ^, if any); see 2.8.3.3.                            1
  10581.  
  10582.     ^        The circumflex shall be special when used                      1
  10583.  
  10584.               - As an anchor (see 2.8.3.5) or,                              1
  10585.  
  10586.               - As the first character of a bracket expression (see         1
  10587.                 2.8.3.2).                                                   1
  10588.  
  10589.     $        The dollar-sign shall be special when used as an anchor.       1
  10590.  
  10591.  2.8.3.1.3  Periods in BREs
  10592.  
  10593.  A period (.), when used outside of a bracket expression, is a BRE that
  10594.  shall match any character in the supported character set except NUL.       1
  10595.  
  10596.  
  10597.  2.8.3.2  RE Bracket Expression
  10598.  
  10599.  A bracket expression (an expression enclosed in square brackets, []) is
  10600.  an RE that matches a single collating element contained in the nonempty    1
  10601.  set of collating elements represented by the bracket expression.           1
  10602.  
  10603.  The following rules and definitions apply to bracket expressions:
  10604.  
  10605.      (1)  A _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n is either a matching list expression or a
  10606.           nonmatching list expression.  It consists of one or more
  10607.           expressions:  collating elements, collating symbols, equivalence  1
  10608.           classes, character classes, or range expressions.  Strictly
  10609.           Conforming POSIX.2 Applications shall not use range expressions,
  10610.           but conforming implementations shall support regular expressions
  10611.           containing range expressions.  The right-bracket (]) shall lose
  10612.           its special meaning and represent itself in a bracket expression
  10613.           if it occurs first in the list [after an initial circumflex (^),
  10614.           if any].  Otherwise, it shall terminate the bracket expression,
  10615.           unless it appears in a collating symbol (such as [.].]) or is     1
  10616.  
  10617.                Copyright c 1991 IEEE.  All rights reserved.
  10618.       This is an unapproved IEEE Standards Draft, subject to change.
  10619.  
  10620.  
  10621.  
  10622.  
  10623.  
  10624.  2.8 Regular Expression Notation                                       131
  10625.  
  10626.  
  10627.  
  10628.  
  10629.  
  10630.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10631.  
  10632.           the ending right-bracket for a collating symbol, equivalence      1
  10633.           class, or character class).  The special characters
  10634.  
  10635.                 .   *   [   \
  10636.  
  10637.           (period, asterisk, left-bracket, and backslash, respectively)
  10638.           shall lose their special meaning within a bracket expression.
  10639.  
  10640.           The character sequences
  10641.  
  10642.                 [.   [=    [:
  10643.  
  10644.           (left-bracket followed by a period, equals-sign, or colon) shall
  10645.           be special inside a bracket expression and are used to delimit
  10646.           collating symbols, equivalence class expressions, and character
  10647.           class expressions.  These symbols shall be followed by a valid
  10648.           expression and the matching terminating sequence .], =], or :],
  10649.           as described in the following items.
  10650.  
  10651.      (2)  A _m_a_t_c_h_i_n_g _l_i_s_t expression specifies a list that shall match any
  10652.           one of the expressions represented in the list.  The first
  10653.           character in the list shall not be the circumflex.  For example,
  10654.           [abc] is an RE that matches any of a, b, or c.
  10655.  
  10656.      (3)  A _n_o_n_m_a_t_c_h_i_n_g _l_i_s_t expression begins with a circumflex (^), and
  10657.           specifies a list that shall match any character or collating
  10658.           element except for the expressions represented in the list after  1
  10659.           the leading circumflex.  For example, [^abc] is an RE that
  10660.           matches any character or collating element except a, b, or c.     1
  10661.           The circumflex shall have this special meaning only when it
  10662.           occurs first in the list, immediately following the left-
  10663.           bracket.
  10664.  
  10665.      (4)  A _c_o_l_l_a_t_i_n_g _s_y_m_b_o_l is a collating element enclosed within
  10666.           bracket-period ([. .]) delimiters.  Collating elements are
  10667.           defined as described in 2.5.2.2.4.  Multicharacter collating      1
  10668.           elements shall be represented as collating symbols when it is
  10669.           necessary to distinguish them from a list of the individual
  10670.           characters that make up the multicharacter collating element.
  10671.           For example, if the string ch is a collating element in the
  10672.           current collation sequence with the associated collating symbol
  10673.           <ch>, the expression [[.ch.]] shall be treated as an RE matching
  10674.           the character sequence ch, while [ch] shall be treated as an RE
  10675.           matching c or h.  Collating symbols shall be recognized only      1
  10676.           inside bracket expressions.  This implies that the RE [[.ch.]]*c
  10677.           shall match the first through fifth character in the string
  10678.           chchch.  If the string is not a collating element in the current
  10679.           collating sequence definition, or if the collating element has    1
  10680.           no characters associated with it (e.g., see the symbol <HIGH> in  1
  10681.  
  10682.  
  10683.                Copyright c 1991 IEEE.  All rights reserved.
  10684.       This is an unapproved IEEE Standards Draft, subject to change.
  10685.  
  10686.  
  10687.  
  10688.  
  10689.  
  10690.  132                                2 Terminology and General Requirements
  10691.  
  10692.  
  10693.  
  10694.  
  10695.  
  10696.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10697.  
  10698.           the example collation definition shown in 2.5.2.2.4), the symbol  1
  10699.           shall be treated as an invalid expression.                        1
  10700.  
  10701.      (5)  An _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s _e_x_p_r_e_s_s_i_o_n shall represent the set of
  10702.           collating elements belonging to an equivalence class, as          1
  10703.           described in 2.5.2.2.4.  Only primary equivalence classes shall   1
  10704.           be recognized.  The class shall be expressed by enclosing any
  10705.           one of the collating elements in the equivalence class within
  10706.           bracket-equal ([= =]) delimiters.  For example, if a, a`, and a^
  10707.           belong to the same equivalence class, then [[=a=]b], [[=a`=]b],
  10708.           and [[=a^=]b] shall each be equivalent to [aa`a^b].  If the
  10709.           collating element does not belong to an equivalence class, the
  10710.           equivalence class expression shall be treated as a _c_o_l_l_a_t_i_n_g
  10711.           _s_y_m_b_o_l.
  10712.  
  10713.      (6)  A _c_h_a_r_a_c_t_e_r _c_l_a_s_s _e_x_p_r_e_s_s_i_o_n shall represent the set of
  10714.           characters belonging to a character class, as defined in the
  10715.           LC_CTYPE category in the current locale.  All character classes
  10716.           specified in the current locale shall be recognized.  A
  10717.           character class expression shall be expressed as a character
  10718.           class name enclosed within ``bracket-colon'' ([: :]) delimiters.
  10719.  
  10720.           Strictly conforming POSIX.2 applications shall only use the
  10721.           following character class expressions, which shall be supported
  10722.           on all conforming implementations:
  10723.  
  10724.                    [:alnum:]   [:cntrl:]   [:lower:]   [:space:]
  10725.                    [:alpha:]   [:digit:]   [:print:]   [:upper:]
  10726.                    [:blank:]   [:graph:]   [:punct:]   [:xdigit:]
  10727.  
  10728.      (7)  A _r_a_n_g_e _e_x_p_r_e_s_s_i_o_n represents the set of collating elements that
  10729.           fall between two elements in the current collation sequence,      1
  10730.           inclusively.  It shall be expressed as the starting point and     1
  10731.           the ending point separated by a hyphen (-).
  10732.  
  10733.           Range expressions shall not be used in Strictly Conforming
  10734.           POSIX.2 Applications because their behavior is dependent on the
  10735.           collating sequence.  Range expressions shall be supported by
  10736.           conforming implementations.
  10737.  
  10738.           In the following, all examples assume the collation sequence
  10739.           specified for the POSIX Locale, unless another collation
  10740.           sequence is specifically defined.
  10741.  
  10742.           The starting range point and the ending range point shall be a
  10743.           collating element or collating symbol.  An equivalence class      2
  10744.           expression used as a starting or ending point of a range          2
  10745.           expression produces unspecified results.  The ending range point  2
  10746.           shall collate equal to or higher than the starting range point;   2
  10747.  
  10748.  
  10749.                Copyright c 1991 IEEE.  All rights reserved.
  10750.       This is an unapproved IEEE Standards Draft, subject to change.
  10751.  
  10752.  
  10753.  
  10754.  
  10755.  
  10756.  2.8 Regular Expression Notation                                       133
  10757.  
  10758.  
  10759.  
  10760.  
  10761.  
  10762.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10763.  
  10764.           otherwise the expression shall be treated as invalid.  The order
  10765.           used is the order in which the collating elements are specified
  10766.           in the current collation definition.  One-to-many mappings (see
  10767.           2.5.2.2) shall not be performed.  For example, assuming that the
  10768.           character eszet (B) is placed in the basic collation sequence
  10769.           after r and s, but before t, and that it maps to the sequence ss
  10770.           for collation purposes, then the expression [r-s] matches only r
  10771.           and s, but the expression [s-t] matches s, B, or t.
  10772.  
  10773.           The interpretation of range expressions where the ending range
  10774.           point also is the starting range point of a subsequent range
  10775.           expression is undefined.
  10776.  
  10777.           The hyphen character shall be treated as itself if it occurs
  10778.           first (after an initial ^, if any) or last in the list, or as an
  10779.           ending range point in a range expression.  As examples, the
  10780.           expressions [-ac] and [ac-] are equivalent and match any of the
  10781.           characters a, c, or -; the expressions [^-ac] and [^ac-] are
  10782.           equivalent and match any characters except a, c, or -; the        1
  10783.           expression [%--] matches any of the characters between % and -    1
  10784.           inclusive; the expression [--@] matches any of the characters
  10785.           between - and @, inclusive; and the expression [a--@] is
  10786.           invalid, because the letter a follows the symbol - in the POSIX
  10787.           Locale.  To use a hyphen as the starting range point, it shall
  10788.           either come first in the bracket expression or be specified as a
  10789.           collating symbol.  For example:  [][.-.]-0], which matches
  10790.           either a right bracket or any character or collating element      1
  10791.           that collates between hyphen and 0, inclusive.                    1
  10792.  
  10793.  
  10794.  2.8.3.3  BREs Matching Multiple Characters
  10795.  
  10796.  The following rules can be used to construct BREs matching multiple
  10797.  characters from BREs matching a single character:
  10798.  
  10799.      (1)  The concatenation of BREs shall match the concatenation of the
  10800.           strings matched by each component of the BRE.                     1
  10801.  
  10802.      (2)  A _s_u_b_e_x_p_r_e_s_s_i_o_n can be defined within a BRE by enclosing it
  10803.           between the character pairs \( and \).  Such a subexpression
  10804.           shall match whatever it would have matched without the \( and
  10805.           \), except that anchoring within subexpressions is optional       1
  10806.           behavior; see 2.8.3.5.  Subexpressions can be arbitrarily         1
  10807.           nested.                                                           1
  10808.  
  10809.      (3)  The _b_a_c_k_r_e_f_e_r_e_n_c_e expression \_n shall match the same (possibly    1
  10810.           empty) string of characters as was matched by a subexpression     1
  10811.           enclosed between \( and \) preceding the \_n. The character _n
  10812.           shall be a digit from 1 through 9, specifying the _n-th
  10813.           subexpression [the one that begins with the _n-th \( and ends
  10814.  
  10815.                Copyright c 1991 IEEE.  All rights reserved.
  10816.       This is an unapproved IEEE Standards Draft, subject to change.
  10817.  
  10818.  
  10819.  
  10820.  
  10821.  
  10822.  134                                2 Terminology and General Requirements
  10823.  
  10824.  
  10825.  
  10826.  
  10827.  
  10828.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10829.  
  10830.           with the corresponding paired \)].  The expression is invalid if
  10831.           less than _n subexpressions precede the \_n.  For example, the
  10832.           expression ^\(.*\)\1$ matches a line consisting of two adjacent
  10833.           appearances of the same string, and the expression \(a\)*\1       2
  10834.           fails to match a.                                                 2
  10835.  
  10836.      (4)  When a BRE matching a single character, a subexpression, or a     1
  10837.           backreference is followed by the special character asterisk (*),  1
  10838.           together with that asterisk it shall match what zero or more      2
  10839.           consecutive occurrences of the BRE would match.  For example,     2
  10840.           [ab]* and [ab][ab] are equivalent when matching the string ab.    2
  10841.  
  10842.      (5)  When a BRE matching a single character, a subexpression, or a     1
  10843.           backreference is followed by an _i_n_t_e_r_v_a_l _e_x_p_r_e_s_s_i_o_n of the        1
  10844.           format \{_m\}, \{_m,\}, or \{_m,_n\}, together with that interval     1
  10845.           expression it shall match what repeated consecutive occurrences   2
  10846.           of the BRE would match.  The values of _m and _n shall be decimal   2
  10847.           integers in the range 0 _< _m _< _n _< {RE_DUP_MAX}, where _m           1
  10848.           specifies the exact or minimum number of occurrences and _n
  10849.           specifies the maximum number of occurrences.  The expression
  10850.           \{_m\} shall match exactly _m occurrences of the preceding BRE,
  10851.           \{_m,\} shall match at least _m occurrences, and \{_m,_n\} shall
  10852.           match any number of occurrences between _m and _n, inclusive.       1
  10853.  
  10854.           For example, in the string abababccccccd the BRE c\{3\} is
  10855.           matched by characters seven through nine, the BRE \(ab\)\{4,\}
  10856.           is not matched at all, and the BRE c\{1,3\}d is matched by
  10857.           characters ten through thirteen.
  10858.  
  10859.  The behavior of multiple adjacent duplication symbols (* and intervals)    1
  10860.  produces undefined results.                                                1
  10861.  
  10862.  
  10863.  2.8.3.4  BRE Precedence                                                    1
  10864.  
  10865.  The order of precedence shall be as shown in Table 2-12, from high to      1
  10866.  low.                                                                       1
  10867.  
  10868.  2.8.3.5  BRE Expression Anchoring
  10869.  
  10870.  A BRE can be limited to matching strings that begin or end a line; this    1
  10871.  is called _a_n_c_h_o_r_i_n_g.  The circumflex and dollar-sign special characters    1
  10872.  shall be considered BRE anchors in the following contexts:                 1
  10873.  
  10874.      (1)  A circumflex (^) shall be an anchor when used as the first        1
  10875.           character of an entire BRE.  The implementation may treat         1
  10876.           circumflex as an anchor when used as the first character of a     1
  10877.           subexpression.  The circumflex shall anchor the expression (or    1
  10878.           optionally subexpression) to the beginning of a string; only      1
  10879.  
  10880.  
  10881.                Copyright c 1991 IEEE.  All rights reserved.
  10882.       This is an unapproved IEEE Standards Draft, subject to change.
  10883.  
  10884.  
  10885.  
  10886.  
  10887.  
  10888.  2.8 Regular Expression Notation                                       135
  10889.  
  10890.  
  10891.  
  10892.  
  10893.  
  10894.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  10895.  
  10896.  
  10897.                        Table 2-12  -  BRE Precedence                        1
  10898.  __________________________________________________________________________________________________________________________________________________  1
  10899.  
  10900.          _c_o_l_l_a_t_i_o_n-_r_e_l_a_t_e_d _b_r_a_c_k_e_t _s_y_m_b_o_l_s   [= =]  [: :]  [. .]            1
  10901.          _e_s_c_a_p_e_d _c_h_a_r_a_c_t_e_r_s                  \<_s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r>           1
  10902.          _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n                  [ ]                            1
  10903.          _s_u_b_e_x_p_r_e_s_s_i_o_n_s/_b_a_c_k_r_e_f_e_r_e_n_c_e_s       \( \) \_n                       1
  10904.          _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r-_B_R_E _d_u_p_l_i_c_a_t_i_o_n    * \{_m,_n\}                      1
  10905.          _c_o_n_c_a_t_e_n_a_t_i_o_n                                                      1
  10906.          _a_n_c_h_o_r_i_n_g                           ^  $                           1
  10907.  __________________________________________________________________________________________________________________________________________________
  10908.  
  10909.  
  10910.           sequences starting at the first character of a string shall be    1
  10911.           matched by the BRE.  For example, the BRE ^ab matches ab in the   1
  10912.           string abcdef, but fails to match in the string cdefab.  The BRE  1
  10913.           \(^ab\) may match the former string.  A portable BRE shall        1
  10914.           escape a leading circumflex in a subexpression to match a         1
  10915.           literal circumflex.                                               1
  10916.  
  10917.      (2)  A dollar-sign ($) shall be an anchor when used as the last        1
  10918.           character of an entire BRE.  The implementation may treat a       1
  10919.           dollar-sign as an anchor when used as the last character of a     1
  10920.           subexpression.  The dollar-sign shall anchor the expression (or   1
  10921.           optionally subexpression) to the end of the string being          1
  10922.           matched; the dollar-sign can be said to match the ``end-of-       1
  10923.           string'' following the last character.                            1
  10924.  
  10925.      (3)  A BRE anchored by both ^ and $ shall match only an entire         2
  10926.           string.  For example, the BRE ^abcdef$ matches strings
  10927.           consisting only of abcdef.                                        1
  10928.  
  10929.  
  10930.  2.8.4  Extended Regular Expressions
  10931.  
  10932.  The _e_x_t_e_n_d_e_d _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n (ERE) notation and construction rules
  10933.  shall apply to utilities defined as using extended regular expressions;
  10934.  any exceptions to the following rules are noted in the descriptions of
  10935.  the specific utilities using EREs.
  10936.  
  10937.  
  10938.  2.8.4.1  EREs Matching a Single Character or Collating Element
  10939.  
  10940.  An ERE ordinary character, a special character preceded by a backslash,    1
  10941.  or a period shall match a single character.  A bracket expression shall    1
  10942.  match a single character or a single collating element.  An _E_R_E _m_a_t_c_h_i_n_g   1
  10943.  _a _s_i_n_g_l_e _c_h_a_r_a_c_t_e_r enclosed in parentheses shall match the same as the
  10944.  ERE without parentheses would have matched.
  10945.  
  10946.  
  10947.                Copyright c 1991 IEEE.  All rights reserved.
  10948.       This is an unapproved IEEE Standards Draft, subject to change.
  10949.  
  10950.  
  10951.  
  10952.  
  10953.  
  10954.  136                                2 Terminology and General Requirements
  10955.  
  10956.  
  10957.  
  10958.  
  10959.  
  10960.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  10961.  
  10962.  2.8.4.1.1  ERE Ordinary Characters
  10963.  
  10964.  An _o_r_d_i_n_a_r_y _c_h_a_r_a_c_t_e_r is an ERE that matches itself.  An ordinary
  10965.  character is any character in the supported character set, except for the  2
  10966.  ERE special characters listed in 2.8.4.1.2.  The interpretation of an      2
  10967.  ordinary character preceded by a backslash (\) is undefined.
  10968.  
  10969.  2.8.4.1.2  ERE Special Characters
  10970.  
  10971.  An _E_R_E _s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r has special properties in certain contexts.       1
  10972.  Outside of those contexts, or when preceded by a backslash, such a         1
  10973.  character shall be an ERE that matches the special character itself.  The
  10974.  extended regular expression special characters and the contexts in which
  10975.  they shall have their special meaning are:
  10976.  
  10977.     . [ \ (     The period, left-bracket, backslash, and left-parenthesis   1
  10978.                 are special except when used in a bracket expression (see   1
  10979.                 2.8.3.2).
  10980.  
  10981.     * + ? {     The asterisk, plus-sign, question-mark, and left-brace are
  10982.                 special except when used in a bracket expression (see
  10983.                 2.8.3.2).  Any of the following uses produce undefined      2
  10984.                 results:                                                    2
  10985.  
  10986.                  - If these characters appear first in an ERE, or
  10987.                    immediately following a vertical-line, circumflex, or
  10988.                    left-parenthesis.
  10989.  
  10990.                  - If a left-brace is not part of a valid interval          1
  10991.                    expression.                                              1
  10992.  
  10993.     |           The vertical-line is special except when used in a bracket
  10994.                 expression (see 2.8.3.2).  A vertical-line appearing first
  10995.                 or last in an ERE, or immediately following a vertical-
  10996.                 line or a left-parentheses, produces undefined results.     1
  10997.  
  10998.     ^           The circumflex shall be special when used                   1
  10999.  
  11000.                  - As an anchor (see 2.8.4.6) or,                           1
  11001.  
  11002.                  - As the first character of a bracket expression (see      1
  11003.                    2.8.3.2).                                                1
  11004.  
  11005.     $           The dollar-sign shall be special when used as an anchor.    1
  11006.  
  11007.  
  11008.  
  11009.  
  11010.  
  11011.  
  11012.  
  11013.                Copyright c 1991 IEEE.  All rights reserved.
  11014.       This is an unapproved IEEE Standards Draft, subject to change.
  11015.  
  11016.  
  11017.  
  11018.  
  11019.  
  11020.  2.8 Regular Expression Notation                                       137
  11021.  
  11022.  
  11023.  
  11024.  
  11025.  
  11026.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11027.  
  11028.  2.8.4.1.3  Periods in EREs
  11029.  
  11030.  A period (.), when used outside of a bracket expression, is an ERE that
  11031.  shall match any character in the supported character set except NUL.       1
  11032.  
  11033.  
  11034.  2.8.4.2  ERE Bracket Expression
  11035.  
  11036.  The rules for ERE Bracket Expressions are the same as for Basic Regular
  11037.  Expressions; see 2.8.3.2.
  11038.  
  11039.  2.8.4.3  EREs Matching Multiple Characters
  11040.  
  11041.  The following rules shall be used to construct EREs matching multiple
  11042.  characters from EREs matching a single character:
  11043.  
  11044.      (1)  A _c_o_n_c_a_t_e_n_a_t_i_o_n _o_f _E_R_E_s shall match the concatenation of the
  11045.           character sequences matched by each component of the ERE.  A      1
  11046.           concatenation of EREs enclosed in parentheses shall match
  11047.           whatever the concatenation without the parentheses matches.  For
  11048.           example, both the ERE cd and the ERE (cd) are matched by the
  11049.           third and fourth character of the string abcdefabcdef.
  11050.  
  11051.      (2)  When an ERE matching a single character, or a concatenation of    1
  11052.           EREs enclosed in parentheses is followed by the special           1
  11053.           character plus-sign (+), together with that plus-sign it shall    1
  11054.           match what one or more consecutive occurrences of the ERE would   2
  11055.           match.  For example, the ERE b+(bc) matches the fourth through    2
  11056.           seventh characters in the string acabbbcde.  And, [ab]+ and       2
  11057.           [ab][ab]* are equivalent.                                         2
  11058.  
  11059.      (3)  When an ERE matching a single character, or a concatenation of    1
  11060.           EREs enclosed in parentheses is followed by the special           1
  11061.           character asterisk (*), together with that asterisk it shall      1
  11062.           match what zero or more consecutive occurrences of the ERE would  2
  11063.           match.  For example, the ERE b*c matches the first character in
  11064.           the string cabbbcde, and the ERE b*cd matches the third through
  11065.           seventh characters in the string cabbbcdebbbbbbcdbc.  And, [ab]*  2
  11066.           and [ab][ab] are equivalent when matching the string ab.          2
  11067.  
  11068.      (4)  When an ERE matching a single character, or a concatenation of    1
  11069.           EREs enclosed in parentheses is followed by the special           1
  11070.           character question-mark (?), together with that question-mark it  1
  11071.           shall match what zero or one consecutive occurrences of the ERE   2
  11072.           would match.  For example, the ERE b?c matches the second         2
  11073.           character in the string acabbbcde.
  11074.  
  11075.      (5)  When an ERE matching a single character, or a concatenation of    1
  11076.           EREs enclosed in parentheses is followed by an _i_n_t_e_r_v_a_l           1
  11077.  
  11078.  
  11079.                Copyright c 1991 IEEE.  All rights reserved.
  11080.       This is an unapproved IEEE Standards Draft, subject to change.
  11081.  
  11082.  
  11083.  
  11084.  
  11085.  
  11086.  138                                2 Terminology and General Requirements
  11087.  
  11088.  
  11089.  
  11090.  
  11091.  
  11092.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11093.  
  11094.           _e_x_p_r_e_s_s_i_o_n of the format {_m}, {_m,}, or {_m,_n}, together with that  1
  11095.           interval expression it shall match what repeated consecutive      2
  11096.           occurrences of the ERE would match.  The values of _m and _n shall  2
  11097.           be decimal integers in the range 0 _< _m _< _n _< {RE_DUP_MAX}, where  1
  11098.           _m specifies the exact or minimum number of occurrences and _n
  11099.           specifies the maximum number of occurrences.  The expression {_m}
  11100.           shall match exactly _m occurrences of the preceding ERE, {_m,}
  11101.           shall match at least _m occurrences, and {_m,_n} shall match any
  11102.           number of occurrences between _m and _n, inclusive.                 1
  11103.  
  11104.           For example, in the string abababccccccd the ERE c{3} is matched  1
  11105.           by characters seven through nine, and the ERE (ab){2,} is         2
  11106.           matched by characters one through six.                            2
  11107.  
  11108.  The behavior of multiple adjacent duplication symbols (+, *, ?, and        1
  11109.  intervals) produces undefined results.                                     1
  11110.  
  11111.  
  11112.  2.8.4.4  ERE Alternation
  11113.  
  11114.  Two EREs separated by the special character vertical-line (|) shall match
  11115.  a string that is matched by either.  For example, the ERE a((bc)|d)
  11116.  matches the string abc and the string ad.  Single characters, or
  11117.  expressions matching single characters, separated by the vertical bar and
  11118.  enclosed in parentheses, shall be treated as an ERE matching a single
  11119.  character.                                                                 1
  11120.  
  11121.  2.8.4.5  ERE Precedence
  11122.  
  11123.  The order of precedence shall be as shown in Table 2-13, from high to      1
  11124.  low.                                                                       1
  11125.  
  11126.  
  11127.                        Table 2-13  -  ERE Precedence                        1
  11128.  __________________________________________________________________________________________________________________________________________________  1
  11129.  
  11130.          _c_o_l_l_a_t_i_o_n-_r_e_l_a_t_e_d _b_r_a_c_k_e_t _s_y_m_b_o_l_s   [= =]  [: :]  [. .]            1
  11131.          _e_s_c_a_p_e_d _c_h_a_r_a_c_t_e_r_s                  \<_s_p_e_c_i_a_l _c_h_a_r_a_c_t_e_r>           1
  11132.          _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n                  [ ]                            1
  11133.          _g_r_o_u_p_i_n_g                            ( )                            1
  11134.          _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r-_E_R_E _d_u_p_l_i_c_a_t_i_o_n    * + ? {_m,_n}                    1
  11135.          _c_o_n_c_a_t_e_n_a_t_i_o_n                                                      1
  11136.          _a_n_c_h_o_r_i_n_g                           ^  $                           1
  11137.          _a_l_t_e_r_n_a_t_i_o_n                         |                              1
  11138.  __________________________________________________________________________________________________________________________________________________
  11139.  
  11140.  
  11141.  For example, the ERE abba|cde matches either the string abba or the        1
  11142.  string cde (because concatenation has a higher order of precedence than    1
  11143.  
  11144.  
  11145.                Copyright c 1991 IEEE.  All rights reserved.
  11146.       This is an unapproved IEEE Standards Draft, subject to change.
  11147.  
  11148.  
  11149.  
  11150.  
  11151.  
  11152.  2.8 Regular Expression Notation                                       139
  11153.  
  11154.  
  11155.  
  11156.  
  11157.  
  11158.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11159.  
  11160.  alternation).
  11161.  
  11162.  
  11163.  2.8.4.6  ERE Expression Anchoring
  11164.  
  11165.  An ERE can be limited to matching strings that begin or end a line; this   1
  11166.  is called _a_n_c_h_o_r_i_n_g.  The circumflex and dollar-sign special characters    1
  11167.  shall be considered ERE anchors in the following contexts:                 1
  11168.  
  11169.      (1)  A circumflex (^) shall be an anchor when used anywhere outside a  1
  11170.           bracket expression.  The circumflex shall anchor the              1
  11171.           (sub)expression to the beginning of a string; only sequences      1
  11172.           starting at the first character of a string shall be matched by   1
  11173.           the ERE.  For example, the EREs ^ab and (^ab) match ab in the     1
  11174.           string abcdef, but fail to match in the string cdefab.            1
  11175.  
  11176.      (2)  A dollar-sign ($) shall be an anchor when used anywhere outside   1
  11177.           a bracket expression.  It shall anchor the expression to the end  1
  11178.           of the string being matched; the dollar-sign can be said to
  11179.           match the ``end-of-string'' following the last character.
  11180.  
  11181.      (3)  An ERE anchored by both ^ and $ shall match only an entire        2
  11182.           string.  For example, the EREs ^abcdef$ and (^abcdef$) match
  11183.           strings consisting only of abcdef.
  11184.  
  11185.  
  11186.  2.8.5  Regular Expression Grammar
  11187.  
  11188.  Grammars describing the syntax of both basic and extended regular
  11189.  expressions are presented in this subclause.  See the grammar conventions
  11190.  in 2.1.2.
  11191.  
  11192.  2.8.5.1  BRE/ERE Grammar Lexical Conventions
  11193.  
  11194.  The lexical conventions for regular expressions shall be as described in
  11195.  this subclause.
  11196.  
  11197.  Except as noted, the longest possible token or delimiter beginning at a
  11198.  given point shall be recognized.
  11199.  
  11200.  The following tokens shall be processed (in addition to those string
  11201.  constants shown in the grammar):
  11202.  
  11203.     COLL_ELEM       Shall be any single-character collating element,
  11204.                     unless it is a META_CHAR.
  11205.  
  11206.     BACKREF         (Applicable only to basic regular expressions.)  Shall
  11207.                     be the character string consisting of '\' followed by
  11208.                     a single-digit numeral, 1 through 9.                    1
  11209.  
  11210.  
  11211.                Copyright c 1991 IEEE.  All rights reserved.
  11212.       This is an unapproved IEEE Standards Draft, subject to change.
  11213.  
  11214.  
  11215.  
  11216.  
  11217.  
  11218.  140                                2 Terminology and General Requirements
  11219.  
  11220.  
  11221.  
  11222.  
  11223.  
  11224.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11225.  
  11226.     DUP_COUNT       Shall represent a numeric constant.  It shall be an
  11227.                     integer in the range 0 _< DUP_COUNT _< {RE_DUP_MAX}.      1
  11228.                     This token shall only be recognized when the context
  11229.                     of the grammar requires it.  At all other times,
  11230.                     digits not preceded by '\' shall be treated as
  11231.                     ORD_CHAR.
  11232.  
  11233.     META_CHAR       Shall be one of the characters:
  11234.  
  11235.                        ^  When found first in a bracket expression
  11236.  
  11237.                        -  When found anywhere but first (after an initial
  11238.                           ^, if any) or last in a bracket expression, or
  11239.                           as the ending range point in a range expression
  11240.  
  11241.                        ]  When found anywhere but first (after an initial
  11242.                           ^, if any) in a bracket expression.
  11243.  
  11244.     L_ANCHOR        (Applicable only to basic regular expressions.)  Shall
  11245.                     be the character ^ when it appears as the first
  11246.                     character of a basic regular expression and when not    1
  11247.                     QUOTED_CHAR.  The ^ may be recognized as an anchor      1
  11248.                     elsewhere; see 2.8.3.5.                                 1
  11249.  
  11250.     ORD_CHAR        Shall be a character, other than one of the special     1
  11251.                     characters in SPEC_CHAR.                                1
  11252.  
  11253.     QUOTED_CHAR     Shall be one of the character sequences:                1
  11254.  
  11255.                           \^      \.      \*      \[      \$      \\        1
  11256.  
  11257.     R_ANCHOR        (Applicable only to basic regular expressions).  Shall  1
  11258.                     be the character $ when it appears as the last          1
  11259.                     character of a basic regular expression and when not    1
  11260.                     QUOTED_CHAR.  The $ may be recognized as an anchor      1
  11261.                     elsewhere; see 2.8.3.5.                                 1
  11262.  
  11263.     SPEC_CHAR       For basic regular expressions, shall be one of the
  11264.                     following special characters:
  11265.  
  11266.                        .     Anywhere outside bracket expressions
  11267.  
  11268.                        \     Anywhere outside bracket expressions
  11269.  
  11270.                        [     Anywhere outside bracket expressions
  11271.  
  11272.                        ^     When an anchor; see 2.8.3.5                    2
  11273.  
  11274.  
  11275.  
  11276.  
  11277.                Copyright c 1991 IEEE.  All rights reserved.
  11278.       This is an unapproved IEEE Standards Draft, subject to change.
  11279.  
  11280.  
  11281.  
  11282.  
  11283.  
  11284.  2.8 Regular Expression Notation                                       141
  11285.  
  11286.  
  11287.  
  11288.  
  11289.  
  11290.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11291.  
  11292.                        $     When an anchor; see 2.8.3.5                    2
  11293.  
  11294.                        *     Anywhere except:  first in an entire RE;
  11295.                              anywhere in a bracket expression; directly
  11296.                              following \(; directly following an anchoring
  11297.                              ^.
  11298.  
  11299.                     For extended regular expressions, shall be one of the
  11300.                     following special characters found anywhere outside
  11301.                     bracket expressions:
  11302.  
  11303.                           ^    .    [    $    (    )    |    *    +    ?    {    \
  11304.  
  11305.                     (The close-parenthesis shall be considered special in   2
  11306.                     this context only if matched with a preceding open-     2
  11307.                     parenthesis.)                                           2
  11308.  
  11309.  
  11310.  2.8.5.2  RE and Bracket Expression Grammar
  11311.  
  11312.  This subclause presents the grammar for basic regular expressions,
  11313.  including the bracket expression grammar that is common to both BREs and
  11314.  EREs.
  11315.  
  11316.  %token   ORD_CHAR QUOTED_CHAR SPEC_CHAR DUP_COUNT
  11317.  
  11318.  %token   BACKREF L_ANCHOR R_ANCHOR
  11319.  
  11320.  %token   Back_open_paren  Back_close_paren
  11321.  /*           '\('           '\)'                           */
  11322.  
  11323.  %token   Back_open_brace  Back_close_brace
  11324.  /*          '\{'              '\}'                       */
  11325.  
  11326.  /*       The following tokens are for the Bracket Expression
  11327.           grammar common to both REs and EREs.              */
  11328.  
  11329.  %token   COLL_ELEM META_CHAR                                               1
  11330.  
  11331.  %token   Open_equal Equal_close Open_dot Dot_close Open_colon Colon_close  1
  11332.  /*          '[='         '=]'      '[.'    '.]'       '[:'        ':]'  */ 1
  11333.  
  11334.  %token   class_name
  11335.  /*       class_name is a keyword to the LC_CTYPE locale category */
  11336.  /*       (representing a character class) in the current locale  */
  11337.  /*       and is only recognized between [: and :]                */
  11338.  
  11339.  %start   basic_reg_exp
  11340.  
  11341.  
  11342.  
  11343.                Copyright c 1991 IEEE.  All rights reserved.
  11344.       This is an unapproved IEEE Standards Draft, subject to change.
  11345.  
  11346.  
  11347.  
  11348.  
  11349.  
  11350.  142                                2 Terminology and General Requirements
  11351.  
  11352.  
  11353.  
  11354.  
  11355.  
  11356.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11357.  
  11358.  %%
  11359.  
  11360.  /*                   --------------------------------------------
  11361.                       Basic Regular Expression
  11362.                       --------------------------------------------
  11363.  */
  11364.  
  11365.  basic_reg_exp      :           RE_expression
  11366.                     | L_ANCHOR
  11367.                     |                        R_ANCHOR
  11368.                     | L_ANCHOR               R_ANCHOR
  11369.                     | L_ANCHOR RE_expression
  11370.                     |          RE_expression R_ANCHOR
  11371.                     | L_ANCHOR RE_expression R_ANCHOR
  11372.                     ;
  11373.  
  11374.  RE_expression      :               simple_RE
  11375.                     | RE_expression simple_RE
  11376.                     ;
  11377.  
  11378.  simple_RE          : nondupl_RE
  11379.                     | nondupl_RE RE_dupl_symbol                               1
  11380.                     ;
  11381.  
  11382.  nondupl_RE         : one_character_RE
  11383.                     | Back_open_paren RE_expression Back_close_paren
  11384.                     | Back_open_paren Back_close_paren
  11385.                     | BACKREF
  11386.                     ;
  11387.  
  11388.  /*                                                                           1
  11389.                       Note:  This grammar does not permit L_ANCHOR or         1
  11390.                       R_ANCHOR inside \( and \) (which implies that ^ and $   1
  11391.                       are ordinary characters).  This reflects the semantic   1
  11392.                       limits on the application, as noted in 2.8.3.5.         1
  11393.                       Implementations are permitted to extend the language to 1
  11394.                       interpret ^ and $ as anchors in these locations, and as 1
  11395.                       such portable applications shall not use unescaped ^    1
  11396.                       and $ in positions inside \( and \) that might be       1
  11397.                       interpreted as anchors.                                 1
  11398.  */                                                                           1
  11399.  
  11400.  one_character_RE   : ORD_CHAR
  11401.                     | QUOTED_CHAR
  11402.                     | '.'
  11403.                     | bracket_expression
  11404.                     ;
  11405.  
  11406.  
  11407.  
  11408.  
  11409.                Copyright c 1991 IEEE.  All rights reserved.
  11410.       This is an unapproved IEEE Standards Draft, subject to change.
  11411.  
  11412.  
  11413.  
  11414.  
  11415.  
  11416.  2.8 Regular Expression Notation                                       143
  11417.  
  11418.  
  11419.  
  11420.  
  11421.  
  11422.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11423.  
  11424.  RE_dupl_symbol     : '*'
  11425.                     | Back_open_brace DUP_COUNT               Back_close_brace
  11426.                     | Back_open_brace DUP_COUNT ','           Back_close_brace
  11427.                     | Back_open_brace DUP_COUNT ',' DUP_COUNT Back_close_brace
  11428.                     ;
  11429.  
  11430.  /*                   --------------------------------------------
  11431.                       Bracket Expression
  11432.                       -------------------------------------------
  11433.  */
  11434.  
  11435.  bracket_expression : '[' matching_list    ']'
  11436.                     | '[' nonmatching_list ']'
  11437.                     ;
  11438.  
  11439.  matching_list      : bracket_list
  11440.                     ;
  11441.  
  11442.  nonmatching_list   : '^' bracket_list
  11443.                     ;
  11444.  
  11445.  bracket_list       : follow_list
  11446.                     | follow_list '-'                                         1
  11447.                     ;
  11448.  
  11449.  follow_list        :             expression_term
  11450.                     | follow_list expression_term
  11451.                     ;
  11452.  
  11453.  expression_term    : single_expression
  11454.                     | range_expression
  11455.                     ;
  11456.  
  11457.  single_expression  : end_range
  11458.                     | character_class                                         1
  11459.                     ;
  11460.  
  11461.  range_expression   : start_range end_range
  11462.                     | start_range '-'
  11463.                     ;
  11464.  
  11465.  start_range        : end_range '-'
  11466.                     ;
  11467.  
  11468.  
  11469.  
  11470.  
  11471.  
  11472.  
  11473.  
  11474.  
  11475.                Copyright c 1991 IEEE.  All rights reserved.
  11476.       This is an unapproved IEEE Standards Draft, subject to change.
  11477.  
  11478.  
  11479.  
  11480.  
  11481.  
  11482.  144                                2 Terminology and General Requirements
  11483.  
  11484.  
  11485.  
  11486.  
  11487.  
  11488.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11489.  
  11490.  end_range          : COLL_ELEM
  11491.                     | collating_symbol
  11492.                                                                             2
  11493.                     ;
  11494.  
  11495.  collating_symbol   : Open_dot COLL_ELEM Dot_close
  11496.                     | Open_dot META_CHAR Dot_close
  11497.                     ;
  11498.  
  11499.  equivalence_class  : Open_equal COLL_ELEM Equal_close
  11500.                     ;
  11501.  
  11502.  character_class    : Open_colon class_name Colon_close                       1
  11503.                     ;
  11504.  
  11505.  
  11506.  2.8.5.3  ERE Grammar
  11507.  
  11508.  This subclause presents the grammar for extended regular expressions,
  11509.  excluding the bracket expression grammar.
  11510.  NOTE:  The bracket expression grammar and the associated %token lines are
  11511.  identical between BREs and EREs.  It has been omitted from the ERE
  11512.  subclause to avoid unnecessary editorial duplication.
  11513.  
  11514.  
  11515.  %token   ORD_CHAR QUOTED_CHAR SPEC_CHAR DUP_COUNT
  11516.  
  11517.  %start   extended_reg_exp
  11518.  
  11519.  %%
  11520.  
  11521.  /*                  --------------------------------------------
  11522.                      Extended Regular Expression
  11523.                      --------------------------------------------
  11524.  */
  11525.  
  11526.  extended_reg_exp  :                      anchored_ERE
  11527.                    |                      nonanchored_ERE
  11528.                    | extended_reg_exp '|' nonanchored_ERE
  11529.                    | extended_reg_exp '|' anchored_ERE
  11530.                    ;
  11531.  
  11532.  
  11533.  
  11534.  
  11535.  
  11536.  
  11537.  
  11538.  
  11539.  
  11540.  
  11541.                Copyright c 1991 IEEE.  All rights reserved.
  11542.       This is an unapproved IEEE Standards Draft, subject to change.
  11543.  
  11544.  
  11545.  
  11546.  
  11547.  
  11548.  2.8 Regular Expression Notation                                       145
  11549.  
  11550.  
  11551.  
  11552.  
  11553.  
  11554.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11555.  
  11556.  anchored_ERE      : '^' nonanchored_ERE
  11557.                    | '^' nonanchored_ERE '$'
  11558.                    |     nonanchored_ERE '$'
  11559.                    | '^'
  11560.                    |                     '$'
  11561.                    | '^'                 '$'
  11562.                    ;
  11563.  
  11564.  nonanchored_ERE   :                 ERE_expression
  11565.                    | nonanchored_ERE ERE_expression
  11566.                    ;
  11567.  
  11568.  ERE_expression    : one_character_ERE
  11569.                    | '(' extended_reg_exp ')'
  11570.                    | ERE_expression ERE_dupl_symbol
  11571.                    ;
  11572.  
  11573.  one_character_ERE : ORD_CHAR
  11574.                    | '\' SPEC_CHAR
  11575.                    | '.'
  11576.                    | bracket_expression
  11577.                    ;
  11578.  
  11579.  ERE_dupl_symbol   : '*'
  11580.                    | '+'
  11581.                    | '?'
  11582.                    | '{' DUP_COUNT               '}'
  11583.                    | '{' DUP_COUNT ','           '}'
  11584.                    | '{' DUP_COUNT ',' DUP_COUNT '}'
  11585.                    ;
  11586.  
  11587.  BEGIN_RATIONALE
  11588.  
  11589.  
  11590.  2.8.6  Regular Expression Notation Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  11591.         _p_a_r_t _o_f _P_1_0_0_3._2)
  11592.  
  11593.  _E_d_i_t_o_r'_s _N_o_t_e:  _S_o_m_e _o_f _t_h_e _t_e_x_t _a_n_d _h_e_a_d_i_n_g_s _o_f _t_h_i_s _r_a_t_i_o_n_a_l_e _h_a_v_e _b_e_e_n  1
  11594.  _r_e_a_r_r_a_n_g_e_d.  _M_o_v_e_d _t_e_x_t _h_a_s _n_o_t _b_e_e_n _d_i_f_f_m_a_r_k_e_d _u_n_l_e_s_s _i_t _c_h_a_n_g_e_d.         1
  11595.  
  11596.  Rather than repeating the description of regular expressions for each
  11597.  utility supporting REs, the working group preferred a common,
  11598.  comprehensive description of regular expressions in one place.  The most
  11599.  common behavior is described here, and exceptions or extensions to this
  11600.  are documented for the respective utilities, if appropriate.
  11601.  
  11602.  The Basic Regular Expression corresponds to the ed or historical grep
  11603.  type, and the Extended Regular Expression corresponds to the historical
  11604.  egrep type (now grep -E).
  11605.  
  11606.  
  11607.                Copyright c 1991 IEEE.  All rights reserved.
  11608.       This is an unapproved IEEE Standards Draft, subject to change.
  11609.  
  11610.  
  11611.  
  11612.  
  11613.  
  11614.  146                                2 Terminology and General Requirements
  11615.  
  11616.  
  11617.  
  11618.  
  11619.  
  11620.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11621.  
  11622.  The text is based on the ed description and substantially modified,
  11623.  primarily to aid developers and others in the understanding of the
  11624.  capabilities and limitations of regular expressions.  Much of this was
  11625.  influenced by the internationalization requirements.
  11626.  
  11627.  It should be noted that the definitions in this clause do not cover the
  11628.  tr utility (see 4.64); the tr syntax does not employ regular expressions.
  11629.  
  11630.  The specification of regular expressions are particularly important to
  11631.  internationalization, because pattern matching operations are very basic
  11632.  operations in business and other operations.  The syntax and rules of
  11633.  regular expressions are intended to be as intuitive as possible, to make
  11634.  them easy to understand and use.  The historical rules and behavior do
  11635.  not provide that capability to non-English-language users, and does not
  11636.  provide the necessary support for commonly used characters and language
  11637.  constructs.  It was necessary to provide extensions to the historical
  11638.  regular expression syntax and rules, to accommodate other languages.
  11639.  Such modifications were proposed by the UniForum Technical Committee
  11640.  Subcommittee on Internationalization and accepted by the working group.
  11641.  As they are limited to bracket expressions, the rationale for these
  11642.  modifications can be found in 2.8.6.3.2.
  11643.  
  11644.  
  11645.  2.8.6.1  Regular Expression Definitions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t
  11646.           _a _p_a_r_t _o_f _P_1_0_0_3._2)
  11647.  
  11648.  The definition of which sequence is matched when several are possible is
  11649.  based on the leftmost-longest rule historically used by deterministic      1
  11650.  recognizers.  This rule is much easier to define and describe, and
  11651.  arguably more useful, than the first-match rule historically used by
  11652.  nondeterministic recognizers.  It is thought that dependencies on the
  11653.  choice of rule are rare; carefully-contrived examples are needed to
  11654.  demonstrate the difference.
  11655.  
  11656.  A formal expression of the leftmost-longest rule is:                       1
  11657.  
  11658.        The search is performed as if all possible suffixes of the
  11659.        string were tested for a prefix matching the pattern; the
  11660.        longest suffix containing a matching prefix is chosen, and
  11661.        the longest possible matching prefix of the chosen suffix is
  11662.        identified as the matching sequence.
  11663.  
  11664.  It is possible to determine what strings correspond to subexpressions by   1
  11665.  recursively applying the leftmost longest rule to each subexpression, but  1
  11666.  only with the proviso that the overall match is leftmost longest (see      1
  11667.  2.8.1.2).  For example, matching \(ac*\)c*d[ac]*\1 against acdacaaa        1
  11668.  should match acdacaaa (with \1=a); simply matching the longest match for   1
  11669.  \(ac*\) would yield \1=ac, but the overall match would be smaller          1
  11670.  (acdac).  In principle, the implementation must examine every possible     1
  11671.  match and among those that yield the leftmost longest total matches, pick  1
  11672.  
  11673.                Copyright c 1991 IEEE.  All rights reserved.
  11674.       This is an unapproved IEEE Standards Draft, subject to change.
  11675.  
  11676.  
  11677.  
  11678.  
  11679.  
  11680.  2.8 Regular Expression Notation                                       147
  11681.  
  11682.  
  11683.  
  11684.  
  11685.  
  11686.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11687.  
  11688.  the one that does the longest match for the leftmost subexpression and so  1
  11689.  on.  Note that this means that matching by subexpressions is context       1
  11690.  dependent:  a subexpression within a larger RE may match a different       1
  11691.  string from the one it would match as an independent RE, and two           1
  11692.  instances of the same subexpression within the same larger RE may match    1
  11693.  different lengths even in similar sequences of characters.  For example,   1
  11694.  in the ERE (a.*b)(a.*b), the two identical subexpressions would match      1
  11695.  four and six characters, respectively, of accbaccccb.  Thus, it is not     1
  11696.  possible to hierarchically decompose the matching problem into smaller,    1
  11697.  independent, matching problems.                                            1
  11698.  
  11699.  Matching is based on the bit pattern used for encoding the character, not
  11700.  on the graphic representation of the character.  This means that if a
  11701.  character set contains two or more encodings for a graphic symbol, or if
  11702.  the strings searched contain text encoded in more than one code set, no
  11703.  attempt is made to search for any other representation of the encoded
  11704.  symbol.  If that is required, the user can specify equivalence classes
  11705.  containing all variations of the desired graphic symbol.
  11706.  
  11707.  The definition of ``single character'' has been expanded to include also
  11708.  collating elements consisting of two or more characters; this expansion    1
  11709.  is applicable only when a bracket expression is included in the BRE or     1
  11710.  ERE.  An example of such a collating element may be the Dutch ``ij'',      1
  11711.  which collates as a ``y.''  In some encodings, a ligature ``i with j''
  11712.  exists _a_s _a _c_h_a_r_a_c_t_e_r, and would represent a single-character collating
  11713.  element.  In another encoding, no such ligature exists, and the two-
  11714.  character sequence ``ij'' is defined as a multicharacter collating
  11715.  element.  Outside brackets, the ``ij'' is treated as a two-character RE
  11716.  and will match the same characters in a string.  Historically, a bracket
  11717.  expression only matched a single character.  If, however, the bracket
  11718.  expression defines, for example, a range that includes ``ij'', then this
  11719.  particular bracket expression will also match a sequence of the two
  11720.  characters ``i'' and ``j'' in the string.
  11721.  
  11722.  
  11723.  2.8.6.2  Regular Expression General Requirements Rationale. (_T_h_i_s
  11724.           _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  11725.  
  11726.  Historically, most regular expression implementations only match lines,
  11727.  not strings.  However, that is more an effect of the usage than of an
  11728.  inherent feature of regular expressions itself.  Consequently, POSIX.2
  11729.  does not regard <newline>s as special; they are ordinary characters, and
  11730.  both a period and a nonmatching list can match them.  Those utilities
  11731.  (like grep) that do not allow <newline>s to match are responsible for
  11732.  eliminating any <newline> from strings before matching against the RE.
  11733.  The _r_e_g_c_o_m_p() function, however, can provide support for such processing
  11734.  without violating the rules of this clause.
  11735.  
  11736.  
  11737.  
  11738.  
  11739.                Copyright c 1991 IEEE.  All rights reserved.
  11740.       This is an unapproved IEEE Standards Draft, subject to change.
  11741.  
  11742.  
  11743.  
  11744.  
  11745.  
  11746.  148                                2 Terminology and General Requirements
  11747.  
  11748.  
  11749.  
  11750.  
  11751.  
  11752.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11753.  
  11754.  The definition of case-insensitive processing is intended to allow
  11755.  matching of multicharacter collating elements as well as characters.  For
  11756.  instance, as each character in the string is matched using both its
  11757.  cases, the RE [[.Ch.]], when matched against char, is in reality matched
  11758.  against ch, Ch, cH, and CH.                                                1
  11759.  
  11760.  Some implementations of egrep have had very limited flexibility in
  11761.  handling complex extended regular expressions.  POSIX.2 does not attempt
  11762.  to define the complexity of a BRE or ERE, but does place a lower limit on
  11763.  it--any regular expression must be handled, as long as it can be
  11764.  expressed in 256 bytes or less.  (Of course, this does not place an upper
  11765.  limit on the implementation.)  There are existing programs using a
  11766.  nondeterministic-recognizer implementation that should have no difficulty
  11767.  with this limit.  It is possible that a good approach would be to attempt
  11768.  to use the faster, but more limited, deterministic recognizer for simple
  11769.  expressions and to fall back on the nondeterministic recognizer for those
  11770.  expressions requiring it.  Nondeterministic implementations must be
  11771.  careful to observe the 2.8.1.2 rules on which match is chosen; the
  11772.  longest match, not the first match, starting at a given character is
  11773.  used.
  11774.  
  11775.  The term ``invalid'' highlights a difference between this clause and some  1
  11776.  others:  POSIX.2 frequently avoids mandating of errors for syntax          1
  11777.  violations because they can be used by implementors to trigger             1
  11778.  extensions.  However, the authors of the internationalization features of  1
  11779.  regular expressions desired to mandate errors for certain conditions to    1
  11780.  identify usage problems or nonportable constructs.  These are identified   1
  11781.  within this rationale as appropriate.  The remaining syntax violations     1
  11782.  have been left implicitly or explicitly undefined.  For example, the BRE   1
  11783.  construct \{1,2,3\} does not comply with the grammar.  A conforming        1
  11784.  application cannot rely on it producing an error nor matching the literal  1
  11785.  characters \{1,2,3\}.  The term ``undefined'' was used in favor of         1
  11786.  ``unspecified'' because many of the situations are considered errors on    1
  11787.  some implementations and it was felt that consistency throughout the       1
  11788.  clause was preferable to mixing undefined and unspecified.                 1
  11789.  
  11790.  
  11791.  2.8.6.3  Basic Regular Expressions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  11792.           _p_a_r_t _o_f _P_1_0_0_3._2)
  11793.  
  11794.  2.8.6.3.1  BREs Matching a Single Character or Collating Element
  11795.             Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  11796.  
  11797.  
  11798.  
  11799.  
  11800.  
  11801.  
  11802.  
  11803.  
  11804.  
  11805.                Copyright c 1991 IEEE.  All rights reserved.
  11806.       This is an unapproved IEEE Standards Draft, subject to change.
  11807.  
  11808.  
  11809.  
  11810.  
  11811.  
  11812.  2.8 Regular Expression Notation                                       149
  11813.  
  11814.  
  11815.  
  11816.  
  11817.  
  11818.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11819.  
  11820.  2.8.6.3.2  RE Bracket Expression Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  11821.             _o_f _P_1_0_0_3._2)
  11822.  
  11823.  If a bracket expression must specify both - and ], then the ] must be
  11824.  placed first (after the ^, if any) and the - last within the bracket
  11825.  expression.
  11826.  
  11827.  Range expressions are, historically, an integral part of regular
  11828.  expressions.  However, the requirements of ``natural language behavior''
  11829.  and portability does conflict: ranges must be treated according to the
  11830.  current collating sequence, and include such characters that fall within
  11831.  the range based on that collating sequence, regardless of character
  11832.  values.  This, however, means that the interpretation will differ
  11833.  depending on collating sequence.  If, for instance, one collating
  11834.  sequence defines ``a'..' as a variant of ``a'', while another defines it as
  11835.  a letter following ``z'', then the expression [a-..z] is valid in the first
  11836.  language and invalid in the second.  This kind of ambiguity should be
  11837.  avoided in portable applications, and therefore the working group elected
  11838.  to state that ranges must not be used in strictly conforming
  11839.  applications; however, implementations must support them.
  11840.  
  11841.  Some historical implementations allow range expressions where the ending
  11842.  range point of one range is also the starting point of the next (for
  11843.  instance [a-m-o]).  This behavior should not be permitted, but to avoid
  11844.  breaking existing implementations, it is now _u_n_d_e_f_i_n_e_d whether it is a
  11845.  valid expression, and how it should be interpreted.
  11846.  
  11847.  Current practice in awk and lex is to accept escape sequences in bracket
  11848.  expressions as per Table 2-15, while the normal regular expression
  11849.  behavior is to regard such a sequence as consisting of two characters.
  11850.  Allowing the awk/lex behavior in regular expressions would change the
  11851.  normal behavior in an unacceptable way; it is expected that awk and lex
  11852.  will decode escape sequences in regular expressions before passing them
  11853.  to _r_e_g_c_o_m_p() or comparable routines.  Each utility describes the escape
  11854.  sequences it accepts as an exception to the rules in this clause; the
  11855.  list is not the same, for historical reasons.
  11856.  
  11857.  As noted earlier, the new syntax and rules have been added to accommodate
  11858.  other languages than English.  These modifications were proposed by the
  11859.  UniForum Subcommittee on Internationalization and accepted by the working
  11860.  group.  The remainder of this clause describes the rationale for these
  11861.  modifications.
  11862.  
  11863.  _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n__R_e_q_u_i_r_e_m_e_n_t_s
  11864.  
  11865.  The goal of the internationalization effort was to provide functions and
  11866.  capabilities that matched the capabilities of existing implementations,
  11867.  but that adhered to the user's local customs, rules, and environment.
  11868.  This has also been described as ``removing the ASCII (and English
  11869.  
  11870.  
  11871.                Copyright c 1991 IEEE.  All rights reserved.
  11872.       This is an unapproved IEEE Standards Draft, subject to change.
  11873.  
  11874.  
  11875.  
  11876.  
  11877.  
  11878.  150                                2 Terminology and General Requirements
  11879.  
  11880.  
  11881.  
  11882.  
  11883.  
  11884.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  11885.  
  11886.  language) bias.''
  11887.  
  11888.  In addition, other requirements also influence the standardization
  11889.  efforts, such as _p_o_r_t_a_b_i_l_i_t_y, _e_x_t_e_n_s_i_b_i_l_i_t_y, and _c_o_m_p_a_t_i_b_i_l_i_t_y.
  11890.  
  11891.  In a worldwide environment _p_o_r_t_a_b_i_l_i_t_y carries much weight.  Wherever
  11892.  feasible, users should be given the capability to develop code that can
  11893.  execute independently of character set, code set, or language.
  11894.  
  11895.  Standards must also be _e_x_t_e_n_s_i_b_l_e; to support further development, to
  11896.  allow for local or regional extensions, or to accommodate new concepts
  11897.  (such as multibyte characters).
  11898.  
  11899.  _C_o_m_p_a_t_i_b_i_l_i_t_y does not only refer to support of existing code, but also
  11900.  to making the new syntax, semantics, and functions compatible with
  11901.  existing environments and implementations.
  11902.  
  11903.  _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n__T_e_c_h_n_i_c_a_l__B_a_c_k_g_r_o_u_n_d
  11904.  
  11905.  The C Standard {7} (and, by implication, also POSIX) recognizes that the
  11906.  ASCII character set used in historical UNIX system implementations is not
  11907.  adequate outside the Anglo-American language area.  It is, however, not
  11908.  enough to remove the ASCII bias; the dependency on Anglo-Saxon
  11909.  conventions and rules must also be broadened to accommodate other
  11910.  cultures, including those that require thousands of characters.
  11911.  
  11912.  Character sets are defined by their _a_t_t_r_i_b_u_t_e_s; typical attributes are
  11913.  the _e_n_c_o_d_i_n_g, the _c_o_l_l_a_t_i_n_g _s_e_q_u_e_n_c_e, the _c_h_a_r_a_c_t_e_r _c_l_a_s_s_i_f_i_c_a_t_i_o_n, and
  11914.  the _c_a_s_e _m_a_p_p_i_n_g.
  11915.  
  11916.  It is also recognized that, even within one language area, several
  11917.  combinations of attributes exist: character set attributes are _m_u_t_a_b_l_e
  11918.  and _c_o_m_b_i_n_a_t_o_r_y.  So, rather than replacing one straitjacket by another,
  11919.  the proposed standards make character sets _u_s_e_r-_d_e_f_i_n_a_b_l_e and _p_r_o_g_r_a_m-
  11920.  _s_e_l_e_c_t_a_b_l_e.
  11921.  
  11922.  The existence of character set attributes is implicit in regular
  11923.  expressions (REs).  This implies that regular expressions must recognize
  11924.  and adapt to the _p_r_o_g_r_a_m-_s_e_l_e_c_t_e_d set of attributes.
  11925.  
  11926.  A program _s_e_l_e_c_t_s the appropriate character set (or combination of
  11927.  attributes) using the mechanism described in 2.5.  The _d_e_f_i_n_i_t_i_o_n of a
  11928.  character set (its attributes) is _e_x_t_e_r_n_a_l to an executing program.  Many
  11929.  combinations of attributes can exist concurrently.  Of particular
  11930.  interest are the following attributes:
  11931.  
  11932.      (1)  _C_o_l_l_a_t_i_n_g _S_e_q_u_e_n_c_e.  In existing implementations, the _e_n_c_o_d_e_d
  11933.           ASCII ordering matches the _l_o_g_i_c_a_l English collating sequence.
  11934.           This correspondence does not exist for all code sets or
  11935.  
  11936.  
  11937.                Copyright c 1991 IEEE.  All rights reserved.
  11938.       This is an unapproved IEEE Standards Draft, subject to change.
  11939.  
  11940.  
  11941.  
  11942.  
  11943.  
  11944.  2.8 Regular Expression Notation                                       151
  11945.  
  11946.  
  11947.  
  11948.  
  11949.  
  11950.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  11951.  
  11952.           languages.  In addition, many languages employ concepts that
  11953.           have no counterparts in English collation:
  11954.  
  11955.            (a)  In many languages, ordering is based on the concept of
  11956.                 _s_t_r_i_n_g _c_o_l_l_a_t_i_o_n rather than _c_h_a_r_a_c_t_e_r _c_o_l_l_a_t_i_o_n as in
  11957.                 English.  One of the effects of this is that the ordering
  11958.                 is based on _c_o_l_l_a_t_i_n_g _e_l_e_m_e_n_t_s rather than on characters.
  11959.                 Characters typically map into collating elements:
  11960.  
  11961.                    _O_n_e-_t_o-_o_n_e mapping, where a character is also a
  11962.                      collating element,
  11963.  
  11964.                    _O_n_e-_t_o-_N mapping, where a single character maps into
  11965.                      two or more collating elements (as the German ``B''
  11966.                      (eszet), which collates as ``ss''),
  11967.  
  11968.                    _N-_t_o-_o_n_e mapping, where two or more characters map into
  11969.                      one collating element (as in the Spanish ``ll'',
  11970.                      which collates between ``l'' and ``m''; i.e., a word
  11971.                      beginning with ``ll'' collates _a_f_t_e_r a word beginning
  11972.                      with ``lo'').
  11973.  
  11974.            (b)  A common method for adding characters to an alphabet is to
  11975.                 use diacritical marks, such as accents or circumflex
  11976.                 (  ^).  In some languages, this creates a completely new
  11977.                 c`h'aracter, collated differently from the Latin ``base.''
  11978.                 In other languages these accented characters are collated
  11979.                 as variants of the Latin base letter; i.e., they have the
  11980.                 same relative order; they are _e_q_u_i_v_a_l_e_n_t.
  11981.  
  11982.                 If the strings (words) being compared are equal except for
  11983.                 ``accents,'' the strings can be ordered based on a
  11984.                 secondary ordering _w_i_t_h_i_n the ``equivalence class.''  For
  11985.                 instance, in French, the words ``_t_a_c_h_e'', ``_t_^a_c_h_e'', and
  11986.                 ``_t_a_c_h_e_t_e_r'' collate in that order.
  11987.  
  11988.           The C Standard {7} recognizes this; it includes new library
  11989.           functions capable of handling complex collation rules.  These
  11990.           functions depend on the setting of the _s_e_t_l_o_c_a_l_e() category
  11991.           LC_COLLATE for a definition of the current collation rules.
  11992.  
  11993.      (2)  _C_h_a_r_a_c_t_e_r _C_l_a_s_s_i_f_i_c_a_t_i_o_n.  Character classification and case
  11994.           mapping is another area where each language (or even language
  11995.           area) has its own rules.  Although users in different countries
  11996.           can use the same code set, such as ISO 8859-1 {5}, the
  11997.           definition of what constitutes a letter or an uppercase letter
  11998.           may vary.
  11999.  
  12000.  
  12001.  
  12002.  
  12003.                Copyright c 1991 IEEE.  All rights reserved.
  12004.       This is an unapproved IEEE Standards Draft, subject to change.
  12005.  
  12006.  
  12007.  
  12008.  
  12009.  
  12010.  152                                2 Terminology and General Requirements
  12011.  
  12012.  
  12013.  
  12014.  
  12015.  
  12016.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12017.  
  12018.           The C Standard {7} recognizes this; library functions used to
  12019.           classify characters or perform case mapping depend on the
  12020.           _s_e_t_l_o_c_a_l_e() category LC_CTYPE for a definition of how characters
  12021.           map to character classes.
  12022.  
  12023.  _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n__P_r_o_p_o_s_a_l__A_r_e_a_s
  12024.  
  12025.  Based on the requirements and attribute characteristics defined above,
  12026.  and after reviewing proposals and definitions by X/Open and other
  12027.  organizations, the UniForum Subcommittee on Internationalization decided
  12028.  to concentrate on the following areas: the range expression, character
  12029.  classes, the definition of one-character RE (multicharacter element), and
  12030.  equivalence classes.
  12031.  
  12032.  Most of these are heavily dependent on the current definition of
  12033.  collation sequence; the Subcommittee felt it natural to couple the
  12034.  capabilities and interpretation of bracket expressions closely to the
  12035.  requirements for extended collation capabilities.
  12036.  
  12037.  In addition, the Subcommittee felt that the capabilities described in 2.5
  12038.  formed a suitable basis for runtime control of regular expression
  12039.  behavior.
  12040.  
  12041.  The Subcommittee realized that the mechanism selected requires changes in
  12042.  the existing syntax.  As a rule, the Subcommittee wished to minimize
  12043.  changes and avoid syntactical changes that may cause existing regular
  12044.  expressions to fail.
  12045.  
  12046.      (1)  _C_o_l_l_a_t_i_n_g _E_l_e_m_e_n_t_s _a_n_d _S_y_m_b_o_l_s.  As noted above, many
  12047.           expressions within a bracket expression are closely connected
  12048.           with collation, and the Subcommittee defined many capabilities
  12049.           in terms of collating elements and collating symbols.
  12050.  
  12051.           A collating element is defined as a sequence of one or more
  12052.           bytes defined in the current collating sequence definition as a
  12053.           unit of collation.  In most cases, a collating element is equal
  12054.           to a character, but the collation sequence may exclude some
  12055.           characters, or define two or more characters as a collating
  12056.           element.
  12057.  
  12058.           A one-character RE is, logically enough, defined as one
  12059.           character or something that translates into one character (the
  12060.           number of bits used to represent the character is not an issue
  12061.           here).  The expression within square brackets is a one-character
  12062.           RE; i.e., single characters are matched against the list of
  12063.           single characters defined within the brackets.
  12064.  
  12065.           In Spanish, the phrase ``a  _t_o _d'' means the sequence of
  12066.           collating elements a, a', b, c, ch, and d.  Consequently, with a
  12067.  
  12068.  
  12069.                Copyright c 1991 IEEE.  All rights reserved.
  12070.       This is an unapproved IEEE Standards Draft, subject to change.
  12071.  
  12072.  
  12073.  
  12074.  
  12075.  
  12076.  2.8 Regular Expression Notation                                       153
  12077.  
  12078.  
  12079.  
  12080.  
  12081.  
  12082.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12083.  
  12084.           Spanish character set, the range statement [a-d] includes the ch
  12085.           collating element, even though it is expressed with two
  12086.           characters (N-to-1 mapping).
  12087.  
  12088.           The historical syntax, however, does not allow the user to
  12089.           define either the range from a through ch, or to define ch as a
  12090.           single character rather than as either c or h.
  12091.  
  12092.           The Subcommittee decided that N-to-1 mappings be recognized (if
  12093.           properly delimited), as _o_n_e-_c_h_a_r_a_c_t_e_r _R_E_s inside, but not
  12094.           outside, square brackets (e.g., a period will never match ch).
  12095.  
  12096.           To be distinguishable from a list of the characters themselves,
  12097.           the multicharacter element must be delimited from the remainder
  12098.           of the characters in the string.  The characters [. _a_n_d .] are
  12099.           used to delimit a multicharacter collating element from other
  12100.           elements, and can be used to delimit single-character collating
  12101.           elements.
  12102.  
  12103.      (2)  _E_q_u_i_v_a_l_e_n_c_e _C_l_a_s_s_e_s.  As stated previously, many languages
  12104.           extend the Latin alphabet by using diacritical marks.  In some
  12105.           cases, the Latin base character (e.g., a) and the accented
  12106.           versions of the base (e.g., a`, a^ in French) constitute a
  12107.           ``subclass'' of characters with some partially equivalent
  12108.           characteristics but different code values.  Because these
  12109.           characters are related, they are often processed as a group.
  12110.           The historical syntax, however, does not provide for this in a
  12111.           portable manner.
  12112.  
  12113.           Although it represents an extension of the historical
  12114.           capabilities, the X/Open group strongly recommended that a
  12115.           properly delimited collating element be recognized as
  12116.           representing an equivalence class, that is as the collating
  12117.           element itself, and all other characters with the same primary
  12118.           order in the collation sequence.
  12119.  
  12120.           The Subcommittee supported this recommendation, and also
  12121.           selected [= and =] as delimiters for equivalence classes.
  12122.  
  12123.      (3)  _R_a_n_g_e _E_x_p_r_e_s_s_i_o_n_s.  The hyphen historically indicated ``a range
  12124.           of consecutive ASCII characters;'' typically it stands for the
  12125.           word ``to,'' as in ``a to z,'' _a_n_d _i_m_p_l_i_e_s _a_n _o_r_d_e_r_e_d _i_n_t_e_r_v_a_l.
  12126.           _I_n _A_S_C_I_I, _t_h_e _e_n_c_o_d_e_d _o_r_d_e_r _m_a_t_c_h_e_s _t_h_e _l_o_g_i_c_a_l _E_n_g_l_i_s_h _o_r_d_e_r;
  12127.           _t_h_i_s _i_s _n_o_t _t_r_u_e _w_i_t_h _o_t_h_e_r _e_n_c_o_d_i_n_g_s _o_r _w_i_t_h _o_t_h_e_r _a_l_p_h_a_b_e_t_s.
  12128.  
  12129.           _I_f _t_h_e _A_S_C_I_I _d_e_p_e_n_d_e_n_c_y _i_s _r_e_m_o_v_e_d, _a_n _a_l_t_e_r_n_a_t_i_v_e _c_o_u_l_d _h_a_v_e
  12130.           _b_e_e_n _t_o _u_s_e _t_h_e _e_n_c_o_d_e_d _s_e_q_u_e_n_c_e _o_f _w_h_a_t_e_v_e_r _c_o_d_e _s_e_t _i_s
  12131.           _c_u_r_r_e_n_t_l_y _u_s_e_d.  _T_h_i_s, _h_o_w_e_v_e_r, _w_o_u_l_d _c_e_r_t_a_i_n_l_y _d_e_c_r_e_a_s_e
  12132.           _p_o_r_t_a_b_i_l_i_t_y, _a_s _w_e_l_l _a_s _r_e_q_u_i_r_i_n_g _t_h_e _u_s_e_r _t_o _k_n_o_w _t_h_e _o_r_d_e_r_i_n_g
  12133.  
  12134.  
  12135.                Copyright c 1991 IEEE.  All rights reserved.
  12136.       This is an unapproved IEEE Standards Draft, subject to change.
  12137.  
  12138.  
  12139.  
  12140.  
  12141.  
  12142.  154                                2 Terminology and General Requirements
  12143.  
  12144.  
  12145.  
  12146.  
  12147.  
  12148.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12149.  
  12150.           _o_f _t_h_e _c_u_r_r_e_n_t _c_o_d_e _s_e_t.  _I_t _w_o_u_l_d _a_l_s_o _m_o_s_t _c_e_r_t_a_i_n_l_y _b_e
  12151.           _c_o_u_n_t_e_r-_i_n_t_u_i_t_i_v_e; _a _F_r_e_n_c_h _u_s_e_r _w_o_u_l_d _e_x_p_e_c_t _t_h_e _e_x_p_r_e_s_s_i_o_n
  12152.           [_a-_d] to match any of the letters a, a` a^, b, c, c, or d.  The
  12153.           Subcommittee regards this interpretation of ranges as most
  12154.           compatible with existing capabilities, and one that provides for
  12155.           the desired portability.
  12156.  
  12157.           As the _l_o_g_i_c_a_l ordering need not be inherent in the _e_n_c_o_d_e_d
  12158.           sequence, an external definition was required.  Such a
  12159.           definition was already present via the _c_o_l_l_a_t_i_n_g _s_e_q_u_e_n_c_e
  12160.           attribute of the character set.  The _s_e_t_l_o_c_a_l_e() function
  12161.           provides for an LC_COLLATE category, which defines the current
  12162.           collating sequence.  The Subcommittee selected this as the basis
  12163.           for the interpretation of ranges, as well as of equivalence
  12164.           classes and multicharacter collating symbols.
  12165.  
  12166.      (4)  _C_h_a_r_a_c_t_e_r _C_l_a_s_s_e_s.  The _r_a_n_g_e expression is commonly used to
  12167.           indicate a _c_h_a_r_a_c_t_e_r _c_l_a_s_s; the _e_x(_a_u__c_m_d) section of the _S_V_I_D
  12168.           states: ``... _a _p_a_i_r _o_f _c_h_a_r_a_c_t_e_r_s _s_e_p_a_r_a_t_e_d _b_y - defines a
  12169.           range (e.g., a-z defines any lowercase letter)....''  In
  12170.           reality, [a-z] means ``any lowercase letter between a and z,
  12171.           inclusive.''  This is _o_n_l_y equivalent to ``any lowercase
  12172.           letter'' if the _a is the first and z is the last lowercase
  12173.           letter in the collating sequence.
  12174.  
  12175.           To provide the intended capabilities in a portable way, the
  12176.           Subcommittee introduced a new syntactical element, namely an
  12177.           explicit _c_h_a_r_a_c_t_e_r _c_l_a_s_s.  The definition of which characters
  12178.           constitute a specific character class is already present via the
  12179.           LC_CTYPE category of the _s_e_t_l_o_c_a_l_e() function.
  12180.  
  12181.           The Subcommittee selected the identification of character
  12182.           classes by _n_a_m_e, bracketed by [: and :].  A character class
  12183.           cannot be used as an endpoint in a range statement.
  12184.  
  12185.  _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n__S_y_n_t_a_x
  12186.  
  12187.  The Subcommittee was careful to propose changes in the regular expression
  12188.  syntax that minimize the impact on existing REs.  In evaluating
  12189.  alternatives, the Subcommittee looked at ease of use (terseness, ease to
  12190.  remember, keyboard availability), impact on historical REs
  12191.  (compatibility), implementability, performance and how error-prone the
  12192.  syntax is likely to be (ambiguity).
  12193.  
  12194.  The Subcommittee made the following evaluation:
  12195.  
  12196.      (1)  Syntax changes must be limited to expressions within square
  12197.           brackets.
  12198.  
  12199.  
  12200.  
  12201.                Copyright c 1991 IEEE.  All rights reserved.
  12202.       This is an unapproved IEEE Standards Draft, subject to change.
  12203.  
  12204.  
  12205.  
  12206.  
  12207.  
  12208.  2.8 Regular Expression Notation                                       155
  12209.  
  12210.  
  12211.  
  12212.  
  12213.  
  12214.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12215.  
  12216.      (2)  Strings or characters with special meaning must be delimited
  12217.           from ordinary strings, to avoid compatibility problems.
  12218.  
  12219.      (3)  Both initial and terminating delimiter should consist of two
  12220.           characters, to minimize compatibility and ambiguity problems.
  12221.  
  12222.      (4)  Outer delimiter character should be bracketing; i.e., naturally
  12223.           indicate initial and terminating side.  Examples:  {} <> ().
  12224.  
  12225.      (5)  The brackets ([]) are, due to the special rules for ``brackets
  12226.           within brackets,'' rather unlikely to be used in the intended
  12227.           way (a closing bracket must precede an open bracket in the
  12228.           existing syntax).
  12229.  
  12230.      (6)  To minimize ambiguity, brackets must be paired with another
  12231.           character.  Many other symbols are already in use, either within
  12232.           regular expressions, or in the shell.  Examples of usable
  12233.           characters are:  =  .  :
  12234.  
  12235.      (7)  Because a multicharacter collating element also can be a member
  12236.           of an equivalence class, different delimiters must be chosen for
  12237.           these two expressions.  Also, the character class expression
  12238.           must be distinguishable from, e.g., multicharacter collating
  12239.           symbols; although no historical example is known to the
  12240.           Subcommittee, prudence dictated that character classes be given
  12241.           separate delimiters.
  12242.  
  12243.      (8)  The Subcommittee selected the period as the secondary delimiter
  12244.           for multicharacter collating symbols.
  12245.  
  12246.      (9)  The Subcommittee selected the equals-sign as the secondary
  12247.           delimiter for equivalence classes.
  12248.  
  12249.     (10)  The Subcommittee selected the colon as the secondary delimiter
  12250.           for character classes.
  12251.  
  12252.  The specific syntax and facilities described in this clause represent a
  12253.  coalescence of proposals and implementations from several vendors.  Due
  12254.  to differences in facilities and syntax, it was not possible to take one
  12255.  implementation and codify it.  There are now several implementations
  12256.  closely patterned on the existing proposal.
  12257.  
  12258.  The facilities presented in this clause are described in a manner that
  12259.  does not preclude their use with multibyte character sets.  However, no
  12260.  attempt has been made to include facilities specifically intended for
  12261.  such character sets.
  12262.  
  12263.  The definitions of character classes is tied to the LC_CTYPE definition.
  12264.  The set of character classes defined in the C Standard {7} represents the
  12265.  
  12266.  
  12267.                Copyright c 1991 IEEE.  All rights reserved.
  12268.       This is an unapproved IEEE Standards Draft, subject to change.
  12269.  
  12270.  
  12271.  
  12272.  
  12273.  
  12274.  156                                2 Terminology and General Requirements
  12275.  
  12276.  
  12277.  
  12278.  
  12279.  
  12280.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12281.  
  12282.  minimum set of character classes required worldwide, i.e., those required
  12283.  by all implementations.  It is the working group's belief that local
  12284.  standards bodies, as well as individual vendors, will provide extensions
  12285.  to the standard in these areas, for instance to provide, for example,
  12286.  Kanji character classes.
  12287.  
  12288.  In many historical implementations, an _i_n_v_a_l_i_d _r_a_n_g_e is treated as if it
  12289.  consisted of the endpoints only.  For example, [z-a] is treated as [za].
  12290.  Some implementations treat the above range as [z], and others as [-az].
  12291.  Neither is correct, and the working group decided that this should be
  12292.  treated as an error.
  12293.  
  12294.  It was proposed that the syntax for bracket expressions be simplified
  12295.  such that the ``extra'' brackets are not needed if the bracket expression
  12296.  only consists of a character class, an equivalence class, or a collating
  12297.  symbol:  ``[:alpha:]'' instead of ``[[:alpha:]]''.  To ensure
  12298.  unambiguity, if a bracket expression starts with :, =, or ., then it
  12299.  cannot contain a class expression or a collating symbol (or duplicated
  12300.  characters).  In addition, it was also proposed that only valid class or
  12301.  collating symbol expressions be accepted: e.g., [[:ctrl:]] is an invalid
  12302.  expression.  The working group rejected the proposal.  While the syntax
  12303.  [:alpha:] may be intuitive to some, the proposal does not allow, e.g.,
  12304.  [:digit:.ch.].  The alternative, to require additional brackets for the
  12305.  latter case would probably cause more errors than the historical syntax.
  12306.  Requiring erroneous class expressions or collating symbols to make the
  12307.  regular expression invalid may minimize the risks for inadvertent
  12308.  spelling errors.  However, at this point it was judged that this would
  12309.  reduce consensus.
  12310.  
  12311.  Consideration was given to eliminating the [.ch.] syntax and providing
  12312.  that collating element should be recognized as such both inside and
  12313.  outside bracket expressions.  In addition, consideration was given to
  12314.  defining character classes such that collating elements are included.
  12315.  The working group rejected these proposals.  The [.ch.] syntax is only
  12316.  required inside bracket expressions due to the fact that a bracket
  12317.  expression historically only matched a single character.  If ch is a
  12318.  collating element, a range [a-z] (if ``ch'' falls within it) matches ch.
  12319.  Outside brackets, an expression ch is treated as two concatenated
  12320.  characters, matching the string ``ch''.  The [.ch.] expression is
  12321.  intended to allow the specification of a multicharacter collating element
  12322.  separately from ranges in a bracket expression.  Character classes are
  12323.  not intended to include collating elements; there is no requirement that
  12324.  all characters in a multicharacter collating element belong to the same
  12325.  character class (for instance ``Ch'' is ``alpha'' but neither ``upper''
  12326.  nor ''lower'').  Introducing collating elements in character classes
  12327.  would be nonintuitive.
  12328.  
  12329.  It was suggested that, because ranges may or may not be meaningful (or
  12330.  even accepted) based on the current collating sequence, they should be
  12331.  
  12332.  
  12333.                Copyright c 1991 IEEE.  All rights reserved.
  12334.       This is an unapproved IEEE Standards Draft, subject to change.
  12335.  
  12336.  
  12337.  
  12338.  
  12339.  
  12340.  2.8 Regular Expression Notation                                       157
  12341.  
  12342.  
  12343.  
  12344.  
  12345.  
  12346.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12347.  
  12348.  eliminated from the syntax (or at least marked obsolescent).  It was
  12349.  suggested that, e.g., [z-a] should always be or never be an error,
  12350.  regardless of collating sequence.  The working group did not wish to
  12351.  eliminate ranges from the syntax.  While it is true that ranges may not
  12352.  be universally portable, they are nevertheless a useful and fundamental
  12353.  construct in regular expressions.  The regular expression syntax has
  12354.  consciously been extended to provide both increased portability and
  12355.  extended local capabilities.  Where supported, ranges must reflect the
  12356.  current collating sequence.  The working group instead elected to include
  12357.  range expressions as an implementation requirement, but state that
  12358.  strictly conforming applications (but not, e.g., National-Body-conforming
  12359.  applications) shall not use range expressions.  Treating erroneous ranges
  12360.  as invalid points out that these may not be portable across collating
  12361.  sequences; and is better than (silently) making them behave in a way
  12362.  contrary to the intents of the user.
  12363.  
  12364.  Earlier drafts allowed the use of an equivalence class expression as the   2
  12365.  starting or ending point of a range expression, such as [[=e=]-f].  This   2
  12366.  now produces unspecified results because it is possible to define the      2
  12367.  equivalence class as a disjoint set of characters.  This example could     2
  12368.  produce different results on various systems:                              2
  12369.  
  12370.      - An error.                                                            2
  12371.  
  12372.      - The equivalent of [[=e=]e-f] (which is the correct portable way to   2
  12373.        include equivalence class effects in a bracket expression).          2
  12374.  
  12375.      - All of the collating elements from the lowest value found in the     2
  12376.        equivalence class, including any of the elements found between the   2
  12377.        disjoint values.                                                     2
  12378.  
  12379.  Consideration was given to saying that equivalence classes with disjoint   2
  12380.  elements produce unspecified results at the start or end of a range, but   2
  12381.  since the application cannot predict which equivalence classes are         2
  12382.  disjoint, this is no improvement over the more general statement chosen.   2
  12383.  
  12384.  It was suggested that, while reference to nonprintable characters is
  12385.  partially supported by the proposed set of character classes, the
  12386.  specificity is not precise enough, and that additional character classes
  12387.  should be supported, e.g., [:tab:] or [:a:].  The working group rejected
  12388.  this proposal, because this feature would represent a substantial
  12389.  enhancement to the current regular expression syntax, and one that cannot
  12390.  be based on internationalization requirements.  It is judged that its
  12391.  inclusion would reduce consensus.  A future revision of regular
  12392.  expressions should study the capability to create temporary character
  12393.  classes for use in regular expressions; a ``character class macro
  12394.  facility.''
  12395.  
  12396.  
  12397.  
  12398.  
  12399.                Copyright c 1991 IEEE.  All rights reserved.
  12400.       This is an unapproved IEEE Standards Draft, subject to change.
  12401.  
  12402.  
  12403.  
  12404.  
  12405.  
  12406.  158                                2 Terminology and General Requirements
  12407.  
  12408.  
  12409.  
  12410.  
  12411.  
  12412.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12413.  
  12414.  2.8.6.3.3  BREs Matching Multiple Characters Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e
  12415.             _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  12416.  
  12417.  The limit of nine backreferences to subexpressions in the RE is based on
  12418.  the use of a single digit identifier; increasing this to multiple digits
  12419.  would break historical applications.  This does not imply that only nine   1
  12420.  subexpressions are allowed in REs.  The following is a valid BRE with ten  1
  12421.  subexpressions:                                                            1
  12422.  
  12423.  \(\(\(ab\)*c\)*d\)\(ef\)*\(gh\)\{2\}\(ij\)*\(kl\)*\(mn\)*\(op\)*\(qr\)*    1
  12424.  
  12425.  The working group regards the common current behavior, which supports
  12426.  \_n*, but not \_n\{_m_i_n,_m_a_x\}, or \(...\)*, or \(...\)\{_m_i_n,_m_a_x\}, as a
  12427.  nonintentional result of a specific implementation, and supports both
  12428.  duplication and interval expressions following subexpressions and
  12429.  backreferences.
  12430.  
  12431.  2.8.6.3.4  Expression Anchoring Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  12432.             _o_f _P_1_0_0_3._2)
  12433.  
  12434.  Often, the dollar-sign is viewed as matching the ending <newline> in text
  12435.  files.  This is not strictly true; the <newline> is typically eliminated
  12436.  from the strings to be matched and the dollar-sign matches the
  12437.  terminating null character.
  12438.  
  12439.  The ability of ^, $, and * to be nonspecial in certain circumstances may   1
  12440.  be confusing to some programmers, but this situation was changed only in   1
  12441.  a minor way from historical practice to avoid breaking many existing       1
  12442.  scripts.  Some consideration was given to making the use of the anchoring  1
  12443.  characters undefined if not escaped and not at the beginning or end of     1
  12444.  strings.  This would cause a number of historical BREs, such as 2^10,      1
  12445.  $HOME, and $1.35, which relied on the characters being treated literally,  1
  12446.  to become invalid.                                                         1
  12447.  
  12448.  However, one relatively uncommon case was changed to allow an extension    1
  12449.  used on some implementations.  Historically, the BREs ^foo and \(^foo\)    1
  12450.  did not match the same string, despite the general rule that               1
  12451.  subexpressions and entire BREs match the same strings.  To achieve         1
  12452.  balloting consensus, POSIX.2 has allowed an extension on some systems to   1
  12453.  treat these two cases in the same way by declaring that anchoring _m_a_y      1
  12454.  occur at the beginning or end of a subexpression.  Therefore, portable     1
  12455.  BREs that require a literal circumflex at the beginning or a dollar-sign   1
  12456.  at the end of a subexpression must escape them.  Note that a BRE such as   1
  12457.  a\(^bc\) will either match a^bc or nothing on different systems under the  1
  12458.  POSIX.2 rules.                                                             1
  12459.  
  12460.  ERE anchoring has been different from BRE anchoring in all historical      1
  12461.  systems.  An unescaped anchor character has never matched its literal      1
  12462.  counterpart outside of a bracket expression.  Some systems treated         1
  12463.  
  12464.  
  12465.                Copyright c 1991 IEEE.  All rights reserved.
  12466.       This is an unapproved IEEE Standards Draft, subject to change.
  12467.  
  12468.  
  12469.  
  12470.  
  12471.  
  12472.  2.8 Regular Expression Notation                                       159
  12473.  
  12474.  
  12475.  
  12476.  
  12477.  
  12478.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12479.  
  12480.  foo$bar as a valid expression that never matched anything, others treated  1
  12481.  it as invalid.  POSIX.2 mandates the former, valid unmatched behavior.     1
  12482.  
  12483.  Some systems have extended the BRE syntax to add alternation.  For         1
  12484.  example, the subexpression \(foo$\|bar\) would match either foo at the     1
  12485.  end of the string or bar anywhere.  The extension is triggered by the use  1
  12486.  of the undefined \| sequence.  Because the BRE is undefined for portable   1
  12487.  scripts, the extending system is free to make other assumptions, such as   1
  12488.  that the $ represents the end-of-line anchor in the middle of a            1
  12489.  subexpression.  If it were not for the extension, the $ would match a      1
  12490.  literal dollar-sign under the POSIX.2 rules.                               1
  12491.  
  12492.  
  12493.  2.8.6.4  Extended Regular Expressions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  12494.           _p_a_r_t _o_f _P_1_0_0_3._2)
  12495.  
  12496.  As with basic regular expressions, the working group decided to make the
  12497.  interpretation of escaped ordinary characters undefined.
  12498.  
  12499.  The right-parenthesis is not listed as an ERE special character because    1
  12500.  it is only special in the context of a preceding left-parenthesis.  If     1
  12501.  found without a preceding left-parenthesis, the right-parenthesis has no   1
  12502.  special meaning.                                                           1
  12503.  
  12504.  Based on objections in several ballots, the _i_n_t_e_r_v_a_l _e_x_p_r_e_s_s_i_o_n, {_m,_n},
  12505.  has been added to extended regular expressions.  Historically, the
  12506.  interval expression has only been supported in some extended regular
  12507.  expression implementations.  The working group estimated that the
  12508.  addition of interval expressions to extended regular expressions would
  12509.  not decrease consensus, and would also make basic regular expressions
  12510.  more of a subset of extended regular expressions than in many historical
  12511.  implementations.
  12512.  
  12513.  It was suggested that, in addition to interval expressions,
  12514.  backreferences (\_n) also should be added to extended regular expressions.
  12515.  This was rejected by the working group as likely to decrease consensus.
  12516.  
  12517.  In historical implementations, multiple duplication symbols are usually
  12518.  interpreted from left to right and treated as additive.  As an example,
  12519.  a+*b matches zero or more instances of a followed by a b.  In POSIX.2,
  12520.  multiple duplication symbols are undefined; i.e., they cannot be relied
  12521.  upon for portable applications.  One reason for this is to provide some
  12522.  scope for future enhancements; the current syntax is very crowded.
  12523.  
  12524.  The precedence of operations differs between EREs and those in lex; in
  12525.  lex, for historical reasons, interval expressions have a lower precedence
  12526.  than concatenation.
  12527.  
  12528.  
  12529.  
  12530.  
  12531.                Copyright c 1991 IEEE.  All rights reserved.
  12532.       This is an unapproved IEEE Standards Draft, subject to change.
  12533.  
  12534.  
  12535.  
  12536.  
  12537.  
  12538.  160                                2 Terminology and General Requirements
  12539.  
  12540.  
  12541.  
  12542.  
  12543.  
  12544.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12545.  
  12546.  2.8.6.5  Regular Expression Grammar Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  12547.           _p_a_r_t _o_f _P_1_0_0_3._2)
  12548.  
  12549.  None.
  12550.  
  12551.  END_RATIONALE
  12552.  
  12553.  
  12554.  
  12555.  2.9  Dependencies on Other Standards
  12556.  
  12557.  
  12558.  2.9.1  Features Inherited from POSIX.1
  12559.  
  12560.  This subclause describes some of the features provided by POSIX.1 {8}
  12561.  that are assumed to be globally available by all systems conforming to
  12562.  POSIX.2.  This subclause does not attempt to detail all of the
  12563.  POSIX.1 {8} features that are required by all of the utilities and
  12564.  functions defined in this standard; the utility and function descriptions
  12565.  point out additional functionality required to provide the corresponding
  12566.  specific features needed by each.
  12567.  
  12568.  The following subclauses describe frequently used concepts.  Utility and
  12569.  function description statements override these defaults when appropriate.
  12570.  
  12571.  BEGIN_RATIONALE
  12572.  
  12573.  2.9.1.0.1  Features Inherited from POSIX.1 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s
  12574.             _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  12575.  
  12576.  It has been pointed out that POSIX.2 assumes that a lot of POSIX.1 {8}
  12577.  functionality is present, but never states exactly how much.  This is an
  12578.  attempt to clarify the assumptions.
  12579.  
  12580.  This subclause only covers the ``utilities and functions defined by this
  12581.  standard.''  It does not mandate that the specific POSIX.1 {8} interfaces
  12582.  themselves be available to all application programs.  A C language
  12583.  program compiled on a POSIX.2 system is not guaranteed that any of the
  12584.  POSIX.1 {8} functions are accessible.  (For example, although UNIX
  12585.  system-based implementations of ls will use _s_t_a_t() to get file status, a
  12586.  POSIX.2 implementation of ls on a ``LONG_NAME_OS-based'' implementation
  12587.  might use the _g_e_t__f_i_l_e__a_t_t_r_i_b_u_t_e_s() and the _g_e_t__f_i_l_e__t_i_m_e__s_t_a_m_p_s() system
  12588.  calls.)  POSIX.2 only requires equivalent functionality, not equal means
  12589.  of access.  In any event, programs requiring the POSIX.1 {8} system
  12590.  interface should specify that they need POSIX.1 {8} conformance and not
  12591.  hope to achieve it by piggybacking on POSIX.2.
  12592.  
  12593.  END_RATIONALE
  12594.  
  12595.  
  12596.  
  12597.                Copyright c 1991 IEEE.  All rights reserved.
  12598.       This is an unapproved IEEE Standards Draft, subject to change.
  12599.  
  12600.  
  12601.  
  12602.  
  12603.  
  12604.  2.9 Dependencies on Other Standards                                   161
  12605.  
  12606.  
  12607.  
  12608.  
  12609.  
  12610.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12611.  
  12612.  2.9.1.1  Process Attributes
  12613.  
  12614.  The following process attributes, as described in POSIX.1 {8}, are
  12615.  assumed to be supported for all processes in POSIX.2:
  12616.  
  12617.             controlling terminal        real group ID
  12618.             current working directory   real user ID
  12619.             effective group ID          root directory
  12620.             effective user ID           saved set-group-ID
  12621.             file descriptors            saved set-user-ID
  12622.             file mode creation mask     session membership
  12623.             process ID                  supplementary group IDs
  12624.             process group ID
  12625.  
  12626.  A conforming implementation may include additional process attributes.
  12627.  
  12628.  BEGIN_RATIONALE
  12629.  
  12630.  2.9.1.1.1  Process Attributes Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  12631.             _P_1_0_0_3._2)
  12632.  
  12633.  The supplementary group IDs requirement is minimal.  If {NGROUPS_MAX} is
  12634.  defined to be zero, they are not required.  If {NGROUPS_MAX} is greater
  12635.  than zero, the supplementary group IDs are used as described in
  12636.  POSIX.1 {8} in various permission checking operations.
  12637.  
  12638.  The saved-set-group-ID and saved-set-user-ID requirements are also
  12639.  minimal.  If {_POSIX_SAVED_IDS} is defined, they are required; otherwise,
  12640.  they are not.
  12641.  
  12642.  A controlling terminal is needed to control access to /dev/tty.
  12643.  
  12644.  The file creation semantics of POSIX.2 require the effective group ID,
  12645.  effective user ID, and the file mode creation mask.
  12646.  
  12647.  Pathname resolution and access permission checks require the current
  12648.  working directory, effective group ID, effective user ID, and root
  12649.  directory.
  12650.  
  12651.  The kill utility requires the effective group ID, effective user ID,
  12652.  process ID, process group ID, real group ID, real user ID, saved set-
  12653.  group-ID, saved set-user-ID, and session membership attributes to perform
  12654.  the various signal addressing and permission checks.
  12655.  
  12656.  The id utility is based on the effective group ID, effective user ID,
  12657.  real group ID, real user ID, and supplementary group IDs.
  12658.  
  12659.  The following process attributes described in POSIX.1 {8} do not seem to
  12660.  be required by POSIX.2:  parent process ID, pending signals, process
  12661.  
  12662.  
  12663.                Copyright c 1991 IEEE.  All rights reserved.
  12664.       This is an unapproved IEEE Standards Draft, subject to change.
  12665.  
  12666.  
  12667.  
  12668.  
  12669.  
  12670.  162                                2 Terminology and General Requirements
  12671.  
  12672.  
  12673.  
  12674.  
  12675.  
  12676.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12677.  
  12678.  signal mask, time left until an alarm clock signal, _t_m_s__c_s_t_i_m_e,
  12679.  _t_m_s__c_u_t_i_m_e, _t_m_s__s_t_i_m_e, and _t_m_s__u_t_i_m_e.  There are probably other
  12680.  attributes mentioned in POSIX.1 {8} that are not listed here.
  12681.  
  12682.  END_RATIONALE
  12683.  
  12684.  
  12685.  2.9.1.2  Concurrent Execution of Processes
  12686.  
  12687.  The following functionality of the POSIX.1 {8} _f_o_r_k() function shall be
  12688.  available on all POSIX.2 conformant systems:
  12689.  
  12690.      (1)  Independent processes shall be capable of executing
  12691.           independently without either process terminating.
  12692.  
  12693.      (2)  A process shall be able to create a new process with all of the
  12694.           attributes referenced in 2.9.1.1, determined according to the
  12695.           semantics of a call to the POSIX.1 {8} _f_o_r_k() function followed
  12696.           by a call in the child process to one of the POSIX.1 {8} _e_x_e_c
  12697.           functions.
  12698.  
  12699.  BEGIN_RATIONALE
  12700.  
  12701.  2.9.1.2.1  Concurrent Execution of Processes Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e
  12702.             _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  12703.  
  12704.  The historical functionality of _f_o_r_k() is required, which permits the
  12705.  concurrent execution of independent processes.  A system with a single
  12706.  thread of process execution is not an appropriate base upon which to
  12707.  build a POSIX.2 system.  (This requirement was not explicitly stated in
  12708.  the 1988 POSIX.1, but is included in the current POSIX.1 {8}.)
  12709.  
  12710.  END_RATIONALE
  12711.  
  12712.  2.9.1.3  File Access Permissions
  12713.  
  12714.  The file access control mechanism described by _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s in
  12715.  2.2.2.55 applies to all files on a conforming POSIX.2 implementation.
  12716.  
  12717.  BEGIN_RATIONALE
  12718.  
  12719.  2.9.1.3.1  File Access Permissions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  12720.             _p_a_r_t _o_f _P_1_0_0_3._2)
  12721.  
  12722.  The entire concept of file protections and access control is assumed to
  12723.  be handled as in POSIX.1 {8}.
  12724.  
  12725.  END_RATIONALE
  12726.  
  12727.  
  12728.  
  12729.                Copyright c 1991 IEEE.  All rights reserved.
  12730.       This is an unapproved IEEE Standards Draft, subject to change.
  12731.  
  12732.  
  12733.  
  12734.  
  12735.  
  12736.  2.9 Dependencies on Other Standards                                   163
  12737.  
  12738.  
  12739.  
  12740.  
  12741.  
  12742.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12743.  
  12744.  2.9.1.4  File Read, Write, and Creation
  12745.  
  12746.  When a file is to be read or written, the file shall be opened with an
  12747.  access mode corresponding to the operation to be performed.  If file
  12748.  access permissions deny access, the requested operation shall fail.
  12749.  
  12750.  When a file that does not exist is created, the following POSIX.1 {8}
  12751.  features shall apply unless the utility or function description states
  12752.  otherwise:
  12753.  
  12754.      (1)  The file's user ID is set to the effective user ID of the
  12755.           calling process.
  12756.  
  12757.      (2)  The file's group ID is set to the effective group ID of the
  12758.           calling process or the group ID of the directory in which the
  12759.           file is being created.
  12760.  
  12761.      (3)  The file's permission bits are set to:
  12762.  
  12763.                 S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR
  12764.  
  12765.           (see POSIX.1 {8} 5.6.1.2) except that the bits specified by the
  12766.           process's file mode creation mask are cleared.
  12767.  
  12768.      (4)  The _s_t__a_t_i_m_e, _s_t__c_t_i_m_e, and _s_t__m_t_i_m_e fields of the file shall be
  12769.           updated as specified in _f_i_l_e _t_i_m_e_s _u_p_d_a_t_e in 2.2.2.69.
  12770.  
  12771.      (5)  If the file is a directory, it shall be an empty directory;
  12772.           otherwise the file shall have length zero.
  12773.  
  12774.      (6)  Unless otherwise specified, the file created shall be a regular
  12775.           file.
  12776.  
  12777.  When an attempt is made to create a file that already exists, the action
  12778.  shall depend on the file type:
  12779.  
  12780.      (1)  For directories and FIFO special files, the attempt shall fail
  12781.           and the utility shall either continue with its operation or exit
  12782.           immediately with a nonzero status, depending on the description
  12783.           of the utility.
  12784.  
  12785.      (2)  For regular files:
  12786.  
  12787.            (a)  The file's user ID, group ID, and permission bits shall
  12788.                 not be changed.
  12789.  
  12790.            (b)  The file shall be truncated to zero length.
  12791.  
  12792.  
  12793.  
  12794.  
  12795.                Copyright c 1991 IEEE.  All rights reserved.
  12796.       This is an unapproved IEEE Standards Draft, subject to change.
  12797.  
  12798.  
  12799.  
  12800.  
  12801.  
  12802.  164                                2 Terminology and General Requirements
  12803.  
  12804.  
  12805.  
  12806.  
  12807.  
  12808.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12809.  
  12810.            (c)  The _s_t__c_t_i_m_e and _s_t__m_t_i_m_e fields shall be marked for
  12811.                 update.
  12812.  
  12813.      (3)  For other file types, the effect is implementation defined.
  12814.  
  12815.  When a file is to be appended, the file shall be opened in a manner
  12816.  equivalent to using the O_APPEND flag, without the O_TRUNC flag, in the
  12817.  POSIX.1 {8} _o_p_e_n() call.
  12818.  
  12819.  BEGIN_RATIONALE
  12820.  
  12821.  2.9.1.4.1  File Read, Write, and Creation Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s
  12822.             _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  12823.  
  12824.  Even though it might be possible for a process to change the mode of a
  12825.  file to match a requested operation and change the mode back to its
  12826.  original state after the operation is completed, utilities are not
  12827.  allowed to do this unless the utility description states otherwise.  As
  12828.  an example, the ed utility r command fails if the file to be read does
  12829.  not exist (even though it could create the file and then read it) or the
  12830.  file permissions do not allow read access [even though it could use the
  12831.  POSIX.1 {8} _c_h_m_o_d() function to make the file readable before attempting
  12832.  to open the file].
  12833.  
  12834.  END_RATIONALE
  12835.  
  12836.  
  12837.  2.9.1.5  File Removal
  12838.  
  12839.  When a directory that is the root directory or current working directory
  12840.  of any process is removed, the effect is implementation defined.  If file
  12841.  access permissions deny access, the requested operation shall fail.
  12842.  Otherwise, when a file is removed:
  12843.  
  12844.      (1)  Its directory entry shall be removed from the file system.
  12845.  
  12846.      (2)  The link count of the file shall be decremented.
  12847.  
  12848.      (3)  If the file is an empty directory (see 2.2.2.43):
  12849.  
  12850.            (a)  If no process has the directory open, the space occupied
  12851.                 by the directory shall be freed and the directory shall no
  12852.                 longer be accessible.
  12853.  
  12854.            (b)  If one or more processes have the directory open, the
  12855.                 directory contents shall be preserved until all references
  12856.                 to the file have been closed.
  12857.  
  12858.  
  12859.  
  12860.  
  12861.                Copyright c 1991 IEEE.  All rights reserved.
  12862.       This is an unapproved IEEE Standards Draft, subject to change.
  12863.  
  12864.  
  12865.  
  12866.  
  12867.  
  12868.  2.9 Dependencies on Other Standards                                   165
  12869.  
  12870.  
  12871.  
  12872.  
  12873.  
  12874.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  12875.  
  12876.      (4)  If the file is a directory that is not empty, the _s_t__c_t_i_m_e field
  12877.           shall be marked for update.
  12878.  
  12879.      (5)  If the file is not a directory:
  12880.  
  12881.            (a)  If the link count becomes zero:
  12882.  
  12883.                  [1]  If no process has the file open, the space occupied
  12884.                       by the file shall be freed and the file shall no
  12885.                       longer be accessible.
  12886.  
  12887.                  [2]  If one or more processes have the file open, the
  12888.                       file contents shall be preserved until all
  12889.                       references to the file have been closed.
  12890.  
  12891.            (b)  If the link count is not reduced to zero, the _s_t__c_t_i_m_e
  12892.                 field shall be marked for update.
  12893.  
  12894.      (6)  The _s_t__c_t_i_m_e and _s_t__m_t_i_m_e fields of the containing directory
  12895.           shall be marked for update.
  12896.  
  12897.  BEGIN_RATIONALE
  12898.  
  12899.  2.9.1.5.1  File Removal Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  12900.             _P_1_0_0_3._2)
  12901.  
  12902.  This is intended to be a summary of the POSIX.1 {8} _u_n_l_i_n_k() and _r_m_d_i_r()
  12903.  requirements needed by POSIX.2.
  12904.  
  12905.  END_RATIONALE
  12906.  
  12907.  
  12908.  2.9.1.6  File Time Values
  12909.  
  12910.  All files have the three time values described by _f_i_l_e _t_i_m_e_s _u_p_d_a_t_e in
  12911.  2.2.2.69.
  12912.  
  12913.  BEGIN_RATIONALE
  12914.  
  12915.  2.9.1.6.1  File Time Values Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  12916.             _P_1_0_0_3._2)
  12917.  
  12918.  All three time stamps specified by POSIX.1 {8} are needed for utilities
  12919.  like find, ls, make, test, and touch to work as expected.
  12920.  
  12921.  END_RATIONALE
  12922.  
  12923.  
  12924.  
  12925.  
  12926.  
  12927.                Copyright c 1991 IEEE.  All rights reserved.
  12928.       This is an unapproved IEEE Standards Draft, subject to change.
  12929.  
  12930.  
  12931.  
  12932.  
  12933.  
  12934.  166                                2 Terminology and General Requirements
  12935.  
  12936.  
  12937.  
  12938.  
  12939.  
  12940.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  12941.  
  12942.  2.9.1.7  File Contents
  12943.  
  12944.  When a reference is made to the contents of a file, _p_a_t_h_n_a_m_e, this means
  12945.  the equivalent of all of the data placed in the space pointed to by _b_u_f
  12946.  when performing the _r_e_a_d() function calls in the following POSIX.1 {8}
  12947.  operations:
  12948.  
  12949.        while (read (fildes, buf, nbytes) > 0)
  12950.                ;
  12951.  
  12952.  If the file is indicated by a pathname _p_a_t_h_n_a_m_e, the file descriptor
  12953.  shall be determined by the equivalent of the following POSIX.1 operation:
  12954.  
  12955.        fildes = open (pathname, O_RDONLY);
  12956.  
  12957.  The value of _n_b_y_t_e_s in the above sequence is unspecified; if the file is
  12958.  of a type where the data returned by _r_e_a_d() would vary with different
  12959.  values, the value shall be one that results in the most data being
  12960.  returned.
  12961.  
  12962.  If the _r_e_a_d() function calls would return an error, it is unspecified
  12963.  whether the contents of the file are considered to include any data from
  12964.  offsets in the file beyond where the error would be returned.
  12965.  
  12966.  BEGIN_RATIONALE
  12967.  
  12968.  2.9.1.7.1  File Contents Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  12969.             _P_1_0_0_3._2)
  12970.  
  12971.  This description is intended to convey the traditional behavior for all
  12972.  types of files.  This matches the intuitive meaning for regular files,
  12973.  but the meaning is not always intuitive for other types of files.  In
  12974.  particular, for FIFOs, pipes, and terminals it must be clear that the
  12975.  contents are not necessarily static at the time a file is opened, but
  12976.  they include the data returned by a sequence of reads until end-of-file
  12977.  is indicated.  This is why the _o_p_e_n() call is specified, with the
  12978.  O_NONBLOCK flag not set.
  12979.  
  12980.  Some files, especially character special files, are sensitive to the size
  12981.  of a _r_e_a_d() request.  The contents of the file are those resulting from
  12982.  proper choice of this size.
  12983.  
  12984.  END_RATIONALE
  12985.  
  12986.  
  12987.  
  12988.  
  12989.  
  12990.  
  12991.  
  12992.  
  12993.                Copyright c 1991 IEEE.  All rights reserved.
  12994.       This is an unapproved IEEE Standards Draft, subject to change.
  12995.  
  12996.  
  12997.  
  12998.  
  12999.  
  13000.  2.9 Dependencies on Other Standards                                   167
  13001.  
  13002.  
  13003.  
  13004.  
  13005.  
  13006.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13007.  
  13008.  2.9.1.8  Pathname Resolution
  13009.  
  13010.  The pathname resolution algorithm described by _p_a_t_h_n_a_m_e _r_e_s_o_l_u_t_i_o_n in
  13011.  2.2.2.104 shall be used by conforming POSIX.2 implementations.  See also
  13012.  _f_i_l_e _h_i_e_r_a_r_c_h_y in 2.2.2.58.
  13013.  
  13014.  BEGIN_RATIONALE
  13015.  
  13016.  2.9.1.8.1  Pathname Resolution Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  13017.             _o_f _P_1_0_0_3._2)
  13018.  
  13019.  The whole concept of hierarchical file systems and pathname resolution is
  13020.  assumed to be handled as in POSIX.1 {8}.
  13021.  
  13022.  END_RATIONALE
  13023.  
  13024.  
  13025.  2.9.1.9  Changing the Current Working Directory                            2
  13026.  
  13027.  When the current working directory (see 2.2.2.159) is to be changed,       2
  13028.  unless the utility or function description states otherwise, the           2
  13029.  operation shall succeed unless a call to the POSIX.1 {8} _c_h_d_i_r() function  2
  13030.  would fail when invoked with the new working directory pathname as its     2
  13031.  argument.                                                                  2
  13032.  
  13033.  2.9.1.9.1  Changing the Current Working Directory Rationale. (_T_h_i_s         2
  13034.             _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)                             2
  13035.  
  13036.  This subclause covers the access permissions and pathname structures       2
  13037.  involved with changing directories, such as with cd or (the UPE-extended)  2
  13038.  mailx utilities.                                                           2
  13039.  
  13040.  2.9.1.10  Establish the Locale
  13041.  
  13042.  The functionality of the POSIX.1 {8} _s_e_t_l_o_c_a_l_e() function is assumed to
  13043.  be available on all POSIX.2 conformant systems; i.e., utilities that
  13044.  require the capability of establishing an international operating
  13045.  environment shall be permitted to set the specified category of the
  13046.  international environment.
  13047.  
  13048.  BEGIN_RATIONALE
  13049.  
  13050.  2.9.1.10.1  Establish the Locale Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  13051.              _o_f _P_1_0_0_3._2)
  13052.  
  13053.  The entire concept of locale categories such as the LC_* variables along
  13054.  with any implementation-defined categories is assumed to be handled as in
  13055.  POSIX.1 {8}.
  13056.  
  13057.  
  13058.  
  13059.                Copyright c 1991 IEEE.  All rights reserved.
  13060.       This is an unapproved IEEE Standards Draft, subject to change.
  13061.  
  13062.  
  13063.  
  13064.  
  13065.  
  13066.  168                                2 Terminology and General Requirements
  13067.  
  13068.  
  13069.  
  13070.  
  13071.  
  13072.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13073.  
  13074.  END_RATIONALE
  13075.  
  13076.  
  13077.  2.9.1.11  Actions Equivalent to POSIX.1 Functions
  13078.  
  13079.  Some utility descriptions specify that a utility performs actions
  13080.  equivalent to a POSIX.1 {8} function.  Such specifications require only
  13081.  that the external effects be equivalent, not that any effect within the
  13082.  utility and visible only to the utility be equivalent.
  13083.  
  13084.  BEGIN_RATIONALE
  13085.  
  13086.  2.9.1.11.1  Actions Equivalent to POSIX.1 Functions Rationale. (_T_h_i_s
  13087.              _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  13088.  
  13089.  An objection was received to an earlier draft that said this approach of
  13090.  equivalent functions was unreasonable, as the reader (and the person
  13091.  writing a test suite) would be responsible for interpreting which
  13092.  portions of POSIX.1 {8} were included and which were not.  For example,
  13093.  would such intermediate effects as the setting of _e_r_r_n_o be required if
  13094.  the related POSIX.1 {8} function called for that?  The answer is no:
  13095.  this standard is only concerned with the end results of functions against
  13096.  the file system and the environment, and not any intermediate values or
  13097.  results visible only to the programmer using the POSIX.1 {8} function in
  13098.  a C (or other high-level language) program.
  13099.  
  13100.  END_RATIONALE
  13101.  
  13102.  
  13103.  2.9.2  Concepts Derived from the C Standard
  13104.  
  13105.  Some of the standard utilities perform complex data manipulation using
  13106.  their own procedure and arithmetic languages, as defined in their
  13107.  Extended Description or Operands subclauses.  Unless otherwise noted, the
  13108.  arithmetic and semantic concepts (precision, type conversion, control
  13109.  flow, etc.) are equivalent to those defined in the C Standard {7}, as
  13110.  described in the following subclauses.  Note that there is no requirement
  13111.  that the standard utilities be implemented in any particular programming
  13112.  language.
  13113.  
  13114.  BEGIN_RATIONALE
  13115.  
  13116.  2.9.2.0.1  Concepts Derived from the C Standard Rationale. (_T_h_i_s
  13117.             _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  13118.  
  13119.  This subclause was introduced to answer complaints that there was
  13120.  insufficient detail presented by such utilities as awk or sh about their
  13121.  procedural control statements and their methods of performing arithmetic
  13122.  functions.  Earlier drafts, derived heavily from the original manual
  13123.  pages, contained statements such as ``for loops similar to the
  13124.  
  13125.                Copyright c 1991 IEEE.  All rights reserved.
  13126.       This is an unapproved IEEE Standards Draft, subject to change.
  13127.  
  13128.  
  13129.  
  13130.  
  13131.  
  13132.  2.9 Dependencies on Other Standards                                   169
  13133.  
  13134.  
  13135.  
  13136.  
  13137.  
  13138.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13139.  
  13140.  C Standard {7},'' which was good enough for a general understanding, but
  13141.  insufficient for a real implementation.
  13142.  
  13143.  The C Standard {7} was selected as a model because most historical
  13144.  implementations of the standard utilities were written in C.  Thus, it is
  13145.  more likely that they will act in a manner desired by POSIX.2 without
  13146.  modification.
  13147.  
  13148.  Using the C Standard {7} is primarily a notational convenience, so the
  13149.  many ``little languages'' in POSIX.2 would not have to be rigorously
  13150.  described in every aspect.  Its selection does not require that the
  13151.  standard utilities be written in Standard C; they could be written in
  13152.  common-usage C, Ada, Pascal, assembler language, or anything else.
  13153.  
  13154.  The sizes of the various numeric values refer to C-language datatypes      1
  13155.  that are allowed to be different sizes by the C Standard {7}.  Thus, like  1
  13156.  a C-language application, a shell application cannot rely on their exact   1
  13157.  size.  However, it can rely on their minimum sizes expressed in the        1
  13158.  C Standard {7}, such as {LONG_MAX} for a _l_o_n_g type.                        1
  13159.  
  13160.  END_RATIONALE                                                              1
  13161.  
  13162.  
  13163.  2.9.2.1  Arithmetic Precision and Operations
  13164.  
  13165.  Integer variables and constants, including the values of operands and
  13166.  option-arguments, used by the standard utilities shall be implemented as
  13167.  equivalent to the C Standard {7} _s_i_g_n_e_d _l_o_n_g data type; floating point
  13168.  shall be implemented as equivalent to the C Standard {7} _d_o_u_b_l_e type.
  13169.  Conversions between types shall be as described in the C Standard {7}.
  13170.  All variables shall be initialized to zero if they are not otherwise
  13171.  assigned by the application's input.
  13172.  
  13173.  Arithmetic operators and functions shall be implemented as equivalent to
  13174.  those in the cited C Standard {7} section, as listed in Table 2-14.
  13175.  
  13176.  The evaluation of arithmetic expressions shall be equivalent to that
  13177.  described in the C Standard {7} section 3.3 Expressions.
  13178.  
  13179.  2.9.2.2  Mathematic Functions
  13180.  
  13181.  Any mathematic functions with the same names as those in the C Standard
  13182.  {7}'s sections:
  13183.  
  13184.     4.5       _M_a_t_h_e_m_a_t_i_c_s <math.h>
  13185.  
  13186.     4.10.2    _P_s_e_u_d_o-_r_a_n_d_o_m _s_e_q_u_e_n_c_e _g_e_n_e_r_a_t_i_o_n _f_u_n_c_t_i_o_n_s
  13187.  
  13188.  
  13189.  
  13190.  
  13191.                Copyright c 1991 IEEE.  All rights reserved.
  13192.       This is an unapproved IEEE Standards Draft, subject to change.
  13193.  
  13194.  
  13195.  
  13196.  
  13197.  
  13198.  170                                2 Terminology and General Requirements
  13199.  
  13200.  
  13201.  
  13202.  
  13203.  
  13204.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13205.  
  13206.  
  13207.              Table 2-14  -  C Standard Operators and Functions
  13208.  
  13209.  _________________________________________________________________________
  13210.  ___________O_p_e_r_a_t_i_o_n________________C__S_t_a_n_d_a_r_d__{_7_}__E_q_u_i_v_a_l_e_n_t__R_e_f_e_r_e_n_c_e____
  13211.    ( )                              _3._3._1 _P_r_i_m_a_r_y _E_x_p_r_e_s_s_i_o_n_s
  13212.  _________________________________________________________________________
  13213.    postfix ++                       _3._3._2 _P_o_s_t_f_i_x _O_p_e_r_a_t_o_r_s
  13214.  __p_o_s_t_f_i_x__-_-______________________________________________________________
  13215.    unary +
  13216.    unary -
  13217.    prefix ++
  13218.    prefix --                        _3._3._3 _U_n_a_r_y _O_p_e_r_a_t_o_r_s
  13219.  
  13220.    ~!
  13221.    sizeof()
  13222.  _________________________________________________________________________
  13223.    *
  13224.    /                                _3._3._5 _M_u_l_t_i_p_l_i_c_a_t_i_v_e _O_p_e_r_a_t_o_r_s
  13225.  __%_______________________________________________________________________
  13226.  | +                             |                                        |
  13227.  | -                             |  _3._3._6 _A_d_d_i_t_i_v_e _O_p_e_r_a_t_o_r_s              |
  13228.  _|________________________________|________________________________________|
  13229.  | <<                            |  _3._3._7 _B_i_t_w_i_s_e _S_h_i_f_t _O_p_e_r_a_t_o_r_s         |
  13230.  _|_>_>______________________________|________________________________________|
  13231.  | <,  <=                        |                                        |
  13232.  | >,  >=                        |  _3._3._8 _R_e_l_a_t_i_o_n_a_l _O_p_e_r_a_t_o_r_s            |
  13233.  _|________________________________|________________________________________|
  13234.  | ==                            |  _3._3._9 _E_q_u_a_l_i_t_y _O_p_e_r_a_t_o_r_s              |
  13235.  _|_!_=______________________________|________________________________________|
  13236.  | &                             |  _3._3._1_0 _B_i_t_w_i_s_e _A_N_D _O_p_e_r_a_t_o_r           |
  13237.  _|________________________________|________________________________________|
  13238.  _|_^_______________________________|____3.___3.___1__1___B__i__t__w__i__s__e___E__x__c__l__u__s__i__v__e___O__R___O__p__e__r__a__t__o__r__|
  13239.  | |                             |  _3._3._1_2 _B_i_t_w_i_s_e _I_n_c_l_u_s_i_v_e _O_R _O_p_e_r_a_t_o_r  |
  13240.  _|________________________________|________________________________________|
  13241.  _|_&_&______________________________|____3.___3.___1__3___L__o__g__i__c__a__l___A__N__D___O__p__e__r__a__t__o__r___________|
  13242.  | ||                            |  _3._3._1_4 _L_o_g_i_c_a_l _O_R _O_p_e_r_a_t_o_r            |
  13243.  _|________________________________|________________________________________|
  13244.  _|___e__x__p__r?___e__x__p__r:___e__x__p__r_________________|____3.___3.___1__5___C__o__n__d__i__t__i__o__n__a__l___O__p__e__r__a__t__o__r___________|
  13245.  | =,  *=,  /=,  %=,  +=,  -=    |                                        |
  13246.  | <<=,  >>=,  &=,  ^=,  |=      |  _3._3._1_6 _A_s_s_i_g_n_m_e_n_t _O_p_e_r_a_t_o_r_s           |
  13247.  _|________________________________|________________________________________|
  13248.  | if ( )                        |                                        |
  13249.  | _i_f ( )  ... else              |  _3._6._4 _S_e_l_e_c_t_i_o_n _S_t_a_t_e_m_e_n_t_s            |
  13250.  _|___s__w__i__t__c__h_(__)______________________|________________________________________|
  13251.  | _w_h_i_l_e ( )                     |                                        |
  13252.  | _d_o ... _w_h_i_l_e ( )              |  _3._6._5 _I_t_e_r_a_t_i_o_n _S_t_a_t_e_m_e_n_t_s            |
  13253.  | _f_o_r ( )                       |                                        |
  13254.  _|________________________________|________________________________________|
  13255.  | _g_o_t_o                          |                                        |
  13256.  |                               |                                        |
  13257.  |             Copyright c 1991 IE|EE.  All rights reserved.               |
  13258.  |    This is an unapproved IEEE S|tandards Draft, subject to change.      |
  13259.  |                               |                                        |
  13260.  |                               |                                        |
  13261.  |                               |                                        |
  13262.  |                               |                                        |
  13263.  |                               |                                        |
  13264.  2|.9 Dependencies on Other Standar|ds                                   171|
  13265.  |                               |                                        |
  13266.  |                               |                                        |
  13267.  |                               |                                        |
  13268.  |                               |                                        |
  13269.  |                               |                                        |
  13270.  P|1003.2/D11.2                   |           INFORMATION TECHNOLOGY--POSIX|
  13271.  |                               |                                        |
  13272.  | _c_o_n_t_i_n_u_e                      |                                        |
  13273.  | _b_r_e_a_k                         |  _3._6._6 _J_u_m_p _S_t_a_t_e_m_e_n_t_s                 |
  13274.  | _r_e_t_u_r_n                        |                                        |
  13275.  _|________________________________|________________________________________|
  13276.  
  13277.  
  13278.  shall be implemented to return the results equivalent to those returned
  13279.  from a call to the corresponding C function described in the
  13280.  C Standard {7}.
  13281.  
  13282.  
  13283.  2.10  Utility Conventions
  13284.  
  13285.  
  13286.  2.10.1  Utility Argument Syntax
  13287.  
  13288.  This subclause describes the argument syntax of the standard utilities
  13289.  and introduces terminology used throughout the standard for describing
  13290.  the arguments processed by the utilities.
  13291.  
  13292.  Within the standard, a special notation is used for describing the syntax
  13293.  of a utility's arguments.  Unless otherwise noted, all utility
  13294.  descriptions use this notation, which is illustrated by this example (see
  13295.  3.9.1):
  13296.  
  13297.  
  13298.        utility_name  [-a] [-b] [-c _o_p_t_i_o_n__a_r_g_u_m_e_n_t] [-d | -e]
  13299.                      [-f_o_p_t_i_o_n__a_r_g_u_m_e_n_t] [_o_p_e_r_a_n_d ...]
  13300.  
  13301.  The notation used for the Synopsis subclauses imposes requirements on the
  13302.  implementors of the standard utilities and provides a simple reference
  13303.  for the reader of the standard.
  13304.  
  13305.      (1)  The utility in the example is named utility_name.  It is
  13306.           followed by _o_p_t_i_o_n_s, _o_p_t_i_o_n-_a_r_g_u_m_e_n_t_s, and _o_p_e_r_a_n_d_s.  The
  13307.           arguments that consist of hyphens and single letters or digits,
  13308.           such as -a, are known as _o_p_t_i_o_n_s (or, historically, _f_l_a_g_s).
  13309.           Certain options are followed by an _o_p_t_i_o_n-_a_r_g_u_m_e_n_t, as shown
  13310.           with [-c _o_p_t_i_o_n__a_r_g_u_m_e_n_t].  The arguments following the last
  13311.           options and option-arguments are named _o_p_e_r_a_n_d_s.
  13312.  
  13313.      (2)  Option-arguments are sometimes shown separated from their
  13314.           options by <blanks>, sometimes directly adjacent.  This reflects
  13315.           the situation that in some cases an option-argument is included
  13316.           within the same argument string as the option; in most cases it
  13317.           is the next argument.  The Utility Syntax Guidelines in 2.10.2
  13318.           require that the option be a separate argument from its option-
  13319.           argument, but there are some exceptions in this standard to
  13320.           ensure continued operation of historical applications:
  13321.  
  13322.  
  13323.                Copyright c 1991 IEEE.  All rights reserved.
  13324.       This is an unapproved IEEE Standards Draft, subject to change.
  13325.  
  13326.  
  13327.  
  13328.  
  13329.  
  13330.  172                                2 Terminology and General Requirements
  13331.  
  13332.  
  13333.  
  13334.  
  13335.  
  13336.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13337.  
  13338.            (a)  If the Synopsis of a standard utility shows a <space>
  13339.                 between an option and option-argument (as with
  13340.                 [-c _o_p_t_i_o_n__a_r_g_u_m_e_n_t] in the example), a conforming
  13341.                 application shall use separate arguments for that option
  13342.                 and its option-argument.
  13343.  
  13344.            (b)  If a <space> is not shown (as with [-f_o_p_t_i_o_n__a_r_g_u_m_e_n_t] in
  13345.                 the example), a conforming application shall place an
  13346.                 option and its option-argument directly adjacent in the
  13347.                 same argument string, without intervening <blank>s.
  13348.  
  13349.            (c)  Notwithstanding the requirements on conforming
  13350.                 applications, a conforming implementation shall permit,
  13351.                 but shall not require, an application to specify options
  13352.                 and option-arguments as separate arguments whether or not
  13353.                 a <space> is shown on the synopsis line.
  13354.  
  13355.            (d)  A standard utility may also be implemented to operate
  13356.                 correctly when the required separation into multiple
  13357.                 arguments is violated by a nonconforming application.
  13358.  
  13359.      (3)  Options are usually listed in alphabetical order unless this
  13360.           would make the utility description more confusing.  There are no
  13361.           implied relationships between the options based upon the order
  13362.           in which they appear, unless otherwise stated in the Options
  13363.           subclause, or unless the exception in 2.10.2 guideline 11
  13364.           applies.  If an option that does not have option-arguments is
  13365.           repeated, the results are undefined, unless otherwise stated.
  13366.  
  13367.      (4)  Frequently, names of parameters that require substitution by
  13368.           actual values are shown with embedded underscores.
  13369.           Alternatively, parameters are shown as follows:
  13370.  
  13371.                 <_p_a_r_a_m_e_t_e_r _n_a_m_e>
  13372.  
  13373.           The angle brackets are used for the symbolic grouping of a
  13374.           phrase representing a single parameter and shall never be
  13375.           included in data submitted to the utility.
  13376.  
  13377.      (5)  When a utility has only a few permissible options, they are
  13378.           sometimes shown individually, as in the example.  Utilities with
  13379.           many flags generally show all of the individual flags (that do
  13380.           not take option-arguments) grouped, as in:
  13381.  
  13382.  
  13383.                 utility_name  [-abcDxyz] [-p _a_r_g] [_o_p_e_r_a_n_d]
  13384.  
  13385.           Utilities with very complex arguments may be shown as follows:
  13386.  
  13387.  
  13388.  
  13389.                Copyright c 1991 IEEE.  All rights reserved.
  13390.       This is an unapproved IEEE Standards Draft, subject to change.
  13391.  
  13392.  
  13393.  
  13394.  
  13395.  
  13396.  2.10 Utility Conventions                                              173
  13397.  
  13398.  
  13399.  
  13400.  
  13401.  
  13402.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13403.  
  13404.                 utility_name  [_o_p_t_i_o_n_s] [_o_p_e_r_a_n_d_s]
  13405.  
  13406.      (6)  Unless otherwise specified, whenever an operand or option-
  13407.           argument is or contains a numeric value:
  13408.  
  13409.            - the number shall be interpreted as a decimal integer.
  13410.  
  13411.            - numerals in the range 0 to 2147483647 shall be syntactically
  13412.              recognized as numeric values.
  13413.  
  13414.            - When the utility description states that it accepts negative
  13415.              numbers as operands or option-arguments, numerals in the
  13416.              range -2147483647 to 2147483647 shall be syntactically
  13417.              recognized as numeric values.
  13418.  
  13419.           This does not mean that all numbers within the allowable range
  13420.           are necessarily semantically correct.  A standard utility that
  13421.           accepts an option-argument or operand that is to be interpreted
  13422.           as a number, and for which a range of values smaller than that
  13423.           shown above is permitted by this standard, describes that
  13424.           smaller range along with the description of the option-argument
  13425.           or operand.  If an error is generated, the utility's diagnostic
  13426.           message shall indicate that the value is out of the supported
  13427.           range, not that it is syntactically incorrect.
  13428.  
  13429.      (7)  Arguments or option-arguments enclosed in the [ and ] notation
  13430.           are optional and can be omitted.  The [ and ] symbols shall
  13431.           never be included in data submitted to the utility.
  13432.  
  13433.      (8)  Arguments separated by the | vertical bar notation are mutually
  13434.           exclusive.  The | symbols shall never be included in data
  13435.           submitted to the utility.  Alternatively, mutually exclusive
  13436.           options and operands may be listed with multiple Synopsis lines.
  13437.           For example:
  13438.  
  13439.  
  13440.                 utility_name  -d [-a] [-c _o_p_t_i_o_n__a_r_g_u_m_e_n_t] [_o_p_e_r_a_n_d ...]
  13441.                 utility_name  -e [-b] [_o_p_e_r_a_n_d ...]
  13442.  
  13443.           When multiple synopsis lines are given for a utility, that is an
  13444.           indication that the utility has mutually exclusive arguments.
  13445.           These mutually exclusive arguments alter the functionality of
  13446.           the utility so that only certain other arguments are valid in
  13447.           combination with one of the mutually exclusive arguments.  Only
  13448.           one of the mutually exclusive arguments is allowed for
  13449.           invocation of the utility.  Unless otherwise stated in an
  13450.           accompanying Options subclause, the relationships between
  13451.           arguments depicted in the Synopsis subclauses are mandatory
  13452.           requirements placed on conforming applications.  The use of
  13453.  
  13454.  
  13455.                Copyright c 1991 IEEE.  All rights reserved.
  13456.       This is an unapproved IEEE Standards Draft, subject to change.
  13457.  
  13458.  
  13459.  
  13460.  
  13461.  
  13462.  174                                2 Terminology and General Requirements
  13463.  
  13464.  
  13465.  
  13466.  
  13467.  
  13468.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13469.  
  13470.           conflicting mutually exclusive arguments produces undefined
  13471.           results, unless a utility description specifies otherwise.  When
  13472.           an option is shown without the [ ] brackets, it means that
  13473.           option is required for that version of the Synopsis.  However,
  13474.           it is not required to be the first argument, as shown in the
  13475.           example above, unless otherwise stated.
  13476.  
  13477.      (9)  Ellipses (...) are used to denote that one or more occurrences
  13478.           of an option or operand are allowed.  When an option or an
  13479.           operand followed by ellipses is enclosed in brackets, zero or
  13480.           more options or operands can be specified.  The forms
  13481.  
  13482.  
  13483.                 utility_name  -f _o_p_t_i_o_n__a_r_g_u_m_e_n_t ...  [_o_p_e_r_a_n_d ...]         1
  13484.                 utility_name  [-g _o_p_t_i_o_n__a_r_g_u_m_e_n_t] ...  [_o_p_e_r_a_n_d ...]
  13485.  
  13486.           indicate that multiple occurrences of the option and its
  13487.           option-argument preceding the ellipses are valid, with semantics
  13488.           as indicated in the Options subclause of the utility.  (See also
  13489.           Guideline 11 in 2.10.2.)  In the first example, each option-      1
  13490.           argument requires a preceding -f and at least one                 1
  13491.           -f _o_p_t_i_o_n__a_r_g_u_m_e_n_t must be given.                                 1
  13492.  
  13493.     (10)  When the synopsis line is too long to be printed on a single
  13494.           line in this document, the indented lines following the initial
  13495.           line are continuation lines.  An actual use of the command would
  13496.           appear on a single logical line.
  13497.  
  13498.  BEGIN_RATIONALE
  13499.  
  13500.  
  13501.  2.10.1.1  Utility Argument Syntax Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  13502.            _p_a_r_t _o_f _P_1_0_0_3._2)
  13503.  
  13504.  This is the subclause where the definitions of _o_p_t_i_o_n, _o_p_t_i_o_n-_a_r_g_u_m_e_n_t,
  13505.  and _o_p_e_r_a_n_d come together.
  13506.  
  13507.  The working group felt that recent trends toward diluting the Synopsis
  13508.  subclauses of historical manual pages to something like:
  13509.  
  13510.        command  [_o_p_t_i_o_n_s] [_o_p_e_r_a_n_d_s]
  13511.  
  13512.  were a disservice to the reader.  Therefore, considerable effort was
  13513.  placed into rigorous definitions of all the command line arguments and
  13514.  their interrelationships.  The relationships depicted in the Synopses are
  13515.  normative parts of this standard; this information is sometimes repeated
  13516.  in textual form, but that is only for clarity within context.
  13517.  
  13518.  
  13519.  
  13520.  
  13521.                Copyright c 1991 IEEE.  All rights reserved.
  13522.       This is an unapproved IEEE Standards Draft, subject to change.
  13523.  
  13524.  
  13525.  
  13526.  
  13527.  
  13528.  2.10 Utility Conventions                                              175
  13529.  
  13530.  
  13531.  
  13532.  
  13533.  
  13534.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13535.  
  13536.  The use of ``undefined'' for conflicting argument usage and for repeated
  13537.  usage of the same option is meant to prevent portable applications from
  13538.  using conflicting arguments or repeated options, unless specifically
  13539.  allowed, as is the case with ls (which allows simultaneous, repeated use
  13540.  of the -C, -l, and -1 options).  Many historical implementations will
  13541.  tolerate this usage, choosing either the first or the last applicable
  13542.  argument, and this tolerance can continue, but portable applications
  13543.  cannot rely upon it.  (Other implementations may choose to print usage
  13544.  messages instead.)
  13545.  
  13546.  The use of ``undefined'' for conflicting argument usage also allows an
  13547.  implementation to make reasonable extensions to utilities where the
  13548.  implementor considers mutually exclusive options according to POSIX.2 to
  13549.  have a sensible meaning and result.
  13550.  
  13551.  POSIX.2 does not define the result of a utility when an option-argument
  13552.  or operand is not followed by ellipses and the application specifies more
  13553.  than one of that option-argument or operand.  This allows an
  13554.  implementation to define valid (although nonstandard) behavior for the
  13555.  utility when more than one such option or operand are specified.
  13556.  
  13557.  Allowing <blank>s after an option (i.e., placing an option and its
  13558.  option-argument into separate argument strings) when the standard does
  13559.  not require it encourages portability of users, while still preserving
  13560.  backward compatibility of scripts.  Inserting <blank>s between the option
  13561.  and the option-argument is preferred; however, historical usage has not
  13562.  been consistent in this area; therefore, <blank>s are required to be
  13563.  handled by all implementations, but implementations are also allowed to
  13564.  handle the historical syntax.  Another justification for selecting the
  13565.  multiple-argument method was that the single-argument case is inherently
  13566.  ambiguous when the option-argument can legitimately be a null string.
  13567.  
  13568.  Wording was also added to explicitly state that digits are permitted as
  13569.  operands and option-arguments.  The lower and upper bounds for the values
  13570.  of the numbers used for operands and option-arguments were derived from
  13571.  the C Standard {7} values for {LONG_MIN} and {LONG_MAX}.  The requirement
  13572.  on the standard utilities is that numbers in the specified range do not
  13573.  cause a syntax error although the specification of a number need not be
  13574.  semantically correct for a particular operand or option-argument of a
  13575.  utility.  For example, the specification of dd obs=3000000000 would yield
  13576.  undefined behavior for the application and would be a syntax error
  13577.  because the number 3000000000 is outside of the range -2147483647 to
  13578.  +2147483647.  On the other hand, dd obs=2000000000 may cause some error,
  13579.  such as ``blocksize too large,'' rather than a syntax error.
  13580.  
  13581.  END_RATIONALE
  13582.  
  13583.  
  13584.  
  13585.  
  13586.  
  13587.                Copyright c 1991 IEEE.  All rights reserved.
  13588.       This is an unapproved IEEE Standards Draft, subject to change.
  13589.  
  13590.  
  13591.  
  13592.  
  13593.  
  13594.  176                                2 Terminology and General Requirements
  13595.  
  13596.  
  13597.  
  13598.  
  13599.  
  13600.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13601.  
  13602.  2.10.2  Utility Syntax Guidelines
  13603.  
  13604.  The following guidelines are established for the naming of utilities and
  13605.  for the specification of options, option-arguments, and operands.  Clause
  13606.  7.5 describes a function that assists utilities in handling options and
  13607.  operands that conform to these guidelines.
  13608.  
  13609.  Operands and option-arguments can contain characters not specified in
  13610.  2.4.
  13611.  
  13612.  The guidelines are intended to provide guidance to the authors of future
  13613.  utilities.  Some of the standard utilities do not conform to all of these
  13614.  guidelines; in those cases, the Options subclauses describe the
  13615.  deviations.
  13616.  
  13617.     Guideline  1:    Utility names should be between two and nine
  13618.                      characters, inclusive.
  13619.  
  13620.     Guideline  2:    Utility names should include lowercase letters (the
  13621.                      lower character classification) from the set
  13622.                      described in 2.4 and digits only.
  13623.  
  13624.     Guideline  3:    Each option name should be a single alphanumeric
  13625.                      character (the alnum character classification) from
  13626.                      the set described in 2.4.  The -W (capital-W) option
  13627.                      shall be reserved for vendor extensions.
  13628.  
  13629.                      NOTE:  The other alphanumeric characters are subject
  13630.                      to standardization in the future, based on historical
  13631.                      usage.  Implementors should be aware that future
  13632.                      POSIX working groups may offer little sympathy to
  13633.                      vendors with isolated extensions in conflict with
  13634.                      future drafts.
  13635.  
  13636.     Guideline  4:    All options should be preceded by the '-' delimiter
  13637.                      character.
  13638.  
  13639.     Guideline  5:    Options without option-arguments should be accepted
  13640.                      when grouped behind one '-' delimiter.
  13641.  
  13642.     Guideline  6:    Each option and option-argument should be a separate
  13643.                      argument, except as noted in 2.10.1, item (2).
  13644.  
  13645.     Guideline  7:    Option-arguments should not be optional.
  13646.  
  13647.     Guideline  8:    When multiple option-arguments are specified to
  13648.                      follow a single option, they should be presented as a
  13649.                      single argument, using commas within that argument or  2
  13650.                      <blank>s within that argument to separate them.
  13651.  
  13652.  
  13653.                Copyright c 1991 IEEE.  All rights reserved.
  13654.       This is an unapproved IEEE Standards Draft, subject to change.
  13655.  
  13656.  
  13657.  
  13658.  
  13659.  
  13660.  2.10 Utility Conventions                                              177
  13661.  
  13662.  
  13663.  
  13664.  
  13665.  
  13666.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13667.  
  13668.     Guideline  9:    All options should precede operands on the command
  13669.                      line.
  13670.  
  13671.     Guideline 10:    The argument "--" should be accepted as a delimiter
  13672.                      indicating the end of options.  Any following
  13673.                      arguments should be treated as operands, even if they
  13674.                      begin with the '-' character.  The "--" argument
  13675.                      should not be used as an option or as an operand.
  13676.  
  13677.     Guideline 11:    The order of different options relative to one
  13678.                      another should not matter, unless the options are
  13679.                      documented as mutually exclusive and such an option
  13680.                      is documented to override any incompatible options
  13681.                      preceding it.  If an option that has option-arguments
  13682.                      is repeated, the option and option-argument
  13683.                      combinations should be interpreted in the order
  13684.                      specified on the command line.
  13685.  
  13686.     Guideline 12:    The order of operands may matter and position-related
  13687.                      interpretations should be determined on a utility-
  13688.                      specific basis.
  13689.  
  13690.     Guideline 13:    For utilities that use operands to represent files to
  13691.                      be opened for either reading or writing, the "-"
  13692.                      operand should be used only to mean standard input
  13693.                      (or standard output when it is clear from context
  13694.                      that an output file is being specified).
  13695.  
  13696.  Any utility claiming conformance to these guidelines shall conform
  13697.  completely to these guidelines, as if these guidelines contained the term
  13698.  ``shall'' instead of ``should,'' except that the utility is permitted to
  13699.  accept usage in violation of these guidelines for backward compatibility
  13700.  as long as the required form is also accepted.
  13701.  
  13702.  Guidelines 1 and 2 are offered as guidance for locales using Latin
  13703.  alphabets.  No recommendations are made by this standard concerning
  13704.  utility naming in other locales.
  13705.  
  13706.  BEGIN_RATIONALE
  13707.  
  13708.  
  13709.  2.10.2.1  Utility Syntax Guidelines Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  13710.            _p_a_r_t _o_f _P_1_0_0_3._2)
  13711.  
  13712.  This subclause is based on the rules listed in the _S_V_I_D.  It was included
  13713.  for two reasons:
  13714.  
  13715.      (1)  The individual utility descriptions in Sections 4, 5, and 6, and
  13716.           Annexes A and C needed a set of common (although not universal)
  13717.           actions on which they could anchor their descriptions of option
  13718.  
  13719.                Copyright c 1991 IEEE.  All rights reserved.
  13720.       This is an unapproved IEEE Standards Draft, subject to change.
  13721.  
  13722.  
  13723.  
  13724.  
  13725.  
  13726.  178                                2 Terminology and General Requirements
  13727.  
  13728.  
  13729.  
  13730.  
  13731.  
  13732.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13733.  
  13734.           and operand syntax.  Most of the standard utilities actually do
  13735.           use these guidelines, and many of their historical
  13736.           implementations use the _g_e_t_o_p_t() function for their parsing.
  13737.           Therefore, it was simpler to cite the rules and merely identify
  13738.           exceptions.
  13739.  
  13740.      (2)  Writers of portable applications need suggested guidelines if
  13741.           the POSIX community is to avoid the chaos of historical UNIX
  13742.           system command syntax.
  13743.  
  13744.  It is recommended that all _f_u_t_u_r_e utilities and applications use these
  13745.  guidelines to enhance ``user portability.''  The fact that some
  13746.  historical utilities could not be changed (to avoid breaking existing
  13747.  applications) should not deter this future goal.
  13748.  
  13749.  The voluntary nature of the guidelines is highlighted by repeated uses of
  13750.  the word _s_h_o_u_l_d throughout.  This usage should not be misinterpreted to
  13751.  imply that utilities that claim conformance in their Options subclauses
  13752.  do not always conform.
  13753.  
  13754.  Guideline 2 recommends the naming of utilities.  In 3.9.1, it is further
  13755.  stated that a command used in the shell command language cannot be named
  13756.  with a trailing colon.
  13757.  
  13758.  Guideline 3 was changed to allow alphanumeric characters (letters and
  13759.  digits) from the character set to allow compatibility with historical
  13760.  usage.  Historical practice allows the use of digits wherever practical;
  13761.  and there are no portability issues that would prohibit the use of
  13762.  digits.  In fact, from an internationalization viewpoint, digits (being
  13763.  nonlanguage dependent) are preferable over letters (a ``-2'' is
  13764.  intuitively self-explanatory to any user, while in the ``-f  _f_i_l_e_n_a_m_e''
  13765.  the letter f is a mnemonic aid only to speakers of Latin based languages
  13766.  where ``filename'' happens to translate to a word that begins with f.
  13767.  Since guideline 3 still retains the word ``single,'' multidigit options
  13768.  are not allowed.  Instances of historical utilities that used them have
  13769.  been marked obsolescent in this standard, with the numbers being changed
  13770.  from option names to option-arguments.
  13771.  
  13772.  It is difficult to come up with a satisfactory solution to the problem of
  13773.  namespace in option characters.  When the POSIX.2 group desired to extend
  13774.  the historical cc utility to accept C Standard {7} programs, it found
  13775.  that all of the portable alphabet was already in use by various vendors.
  13776.  Thus, it had to devise a new name, c89, rather than something like cc -X.
  13777.  There were suggestions that implementors be restricted to providing
  13778.  extensions through various means (such as using a plus-sign as the option
  13779.  delimiter or using option characters outside the alphanumeric set) that
  13780.  would reserve all of the remaining alphanumeric characters for future
  13781.  POSIX standards.  These approaches were resisted because they lacked the
  13782.  historical style of UNIX.  Furthermore, if a vendor-provided option
  13783.  
  13784.  
  13785.                Copyright c 1991 IEEE.  All rights reserved.
  13786.       This is an unapproved IEEE Standards Draft, subject to change.
  13787.  
  13788.  
  13789.  
  13790.  
  13791.  
  13792.  2.10 Utility Conventions                                              179
  13793.  
  13794.  
  13795.  
  13796.  
  13797.  
  13798.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13799.  
  13800.  should become commonly used in the industry, it would be a candidate for
  13801.  standardization.  It would be desireable to standardize such a feature
  13802.  using existing practice for the syntax (the semantics can be standardized
  13803.  with any syntax).  This would not be possible if the syntax was one
  13804.  reserved for the vendor.  However, since the standardization process may
  13805.  lead to minor changes in the semantics, it may prove to be better for a
  13806.  vendor to use a syntax that will not be affected by standardization.  As
  13807.  a compromise, the following statements are made by the developers of
  13808.  POSIX.2:
  13809.  
  13810.      - In future revisions to this standard, and in other POSIX standards,
  13811.        every attempt will be made to develop new utilities and features
  13812.        that conform to the Utility Syntax Guidelines.
  13813.  
  13814.      - Future extensions and additions to POSIX standards will not use the
  13815.        -W (capital W) option.  This option is forever reserved to
  13816.        implementors for extensions, in a manner reminiscent of the
  13817.        option's use in historical versions of the cc utility.  The other
  13818.        alphanumeric characters are subject to standardization in the
  13819.        future, based on historical usage.
  13820.  
  13821.  Implementors should be cognizant of these intentions and aware that
  13822.  future POSIX working groups will offer little sympathy to vendors with
  13823.  extensions in conflict with future drafts.  In the first version of
  13824.  POSIX.2, vendors held a virtual veto power when conflicts arose with
  13825.  their extensions; in the future, POSIX working groups may be less
  13826.  concerned about preserving isolated extensions that conflict with these
  13827.  statements of intent.
  13828.  
  13829.  Guideline 8 includes the concept of comma-separated lists in a single
  13830.  argument.  It is up to the utility to parse such a list itself because
  13831.  _g_e_t_o_p_t() just returns the single string.  This situation was retained so
  13832.  that certain historical utilities wouldn't violate the guidelines.
  13833.  Applications preparing for international use should be aware of an
  13834.  occasional problem with comma-separated lists:  in some locales, the
  13835.  comma is used as the radix character.  Thus, if an application is
  13836.  preparing operands for a utility that expects a comma-separated lists, it
  13837.  should avoid generating noninteger values through one of the means that
  13838.  is influenced by setting the LC_NUMERIC variable [such as awk, bc,
  13839.  printf, or _p_r_i_n_t_f()].
  13840.  
  13841.  Applications calling any utility with a first operand starting with "-"
  13842.  should usually specify "--", as indicated by Guideline 10, to mark the
  13843.  end of the options.  This is true even if the Synopsis in this standard
  13844.  does not specify any options; implementations may provide options as
  13845.  extensions to this standard.  The standard utilities that do not support
  13846.  Guideline 10 indicate that fact in the Options subclause of the utility
  13847.  description.
  13848.  
  13849.  
  13850.  
  13851.                Copyright c 1991 IEEE.  All rights reserved.
  13852.       This is an unapproved IEEE Standards Draft, subject to change.
  13853.  
  13854.  
  13855.  
  13856.  
  13857.  
  13858.  180                                2 Terminology and General Requirements
  13859.  
  13860.  
  13861.  
  13862.  
  13863.  
  13864.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13865.  
  13866.  Guideline 11 was modified to clarify that the order of different options
  13867.  should not matter relative to one another.  However, the order of
  13868.  repeated options that also have option-arguments may be significant;
  13869.  therefore, such options are required to be interpreted in the order that
  13870.  they are specified.  The make utility is an instance of a historical
  13871.  utility that uses repeated options in which the order is significant.
  13872.  Multiple files are specified by giving multiple instances of the -f
  13873.  option, for example:
  13874.  
  13875.        make -f common_header -f specific_rules target
  13876.  
  13877.  Guideline 13 does not imply that all of the standard utilities
  13878.  automatically accept the operand "-" to mean standard input or output,
  13879.  nor does it specify the actions of the utility upon encountering multiple
  13880.  "-" operands.  It simply says that, by default, "-" operands shall not be
  13881.  used for other purposes in the file reading/writing [but not _s_t_a_t()ing,
  13882.  _u_n_l_i_n_k()ing, touch_i_n_g, etc.] utilities.  All information concerning
  13883.  actual treatment of the "-" operand is found in the individual utility
  13884.  clauses.
  13885.  
  13886.  An area of concern that was expressed during the balloting process was
  13887.  that as implementations mature implementation-defined utilities and
  13888.  implementation-defined utility options will result.  The notion was
  13889.  expressed that there needed to be a standard way, say an environment
  13890.  variable or some such mechanism, to identify implementation-defined
  13891.  utilities separately from standard utilities that may have the same name.
  13892.  It was decided that there already exist several ways of dealing with this
  13893.  situation and that it is outside of the scope of the standard to attempt
  13894.  to standardize in the area of nonstandard items.  A method that exists on
  13895.  some historical implementations is the use of the so-called /local/bin or
  13896.  /usr/local/bin directory to separate local or additional copies or
  13897.  versions of utilities.  Another method that is also used is to isolate
  13898.  utilities into completely separate domains.  Still another method to
  13899.  ensure that the desired utility is being used is to request the utility
  13900.  by its full pathname.  There are, to be sure, many approaches to this
  13901.  situation; the examples given above serve to illustrate that there is
  13902.  more than one.
  13903.  
  13904.  END_RATIONALE
  13905.  
  13906.  
  13907.  
  13908.  
  13909.  
  13910.  
  13911.  
  13912.  
  13913.  
  13914.  
  13915.  
  13916.  
  13917.                Copyright c 1991 IEEE.  All rights reserved.
  13918.       This is an unapproved IEEE Standards Draft, subject to change.
  13919.  
  13920.  
  13921.  
  13922.  
  13923.  
  13924.  2.10 Utility Conventions                                              181
  13925.  
  13926.  
  13927.  
  13928.  
  13929.  
  13930.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  13931.  
  13932.  2.11  Utility Description Defaults
  13933.  
  13934.  This clause describes all of the subclauses used within the utility
  13935.  clauses in Section 4 and the other sections that describe standard
  13936.  utilities.  It describes:
  13937.  
  13938.      (1)  Intended usage of the subclause.
  13939.  
  13940.      (2)  Global defaults that affect all the standard utilities.
  13941.  
  13942.  BEGIN_RATIONALE
  13943.  
  13944.  
  13945.  2.11.0.1  Utility Description Defaults Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t
  13946.            _a _p_a_r_t _o_f _P_1_0_0_3._2)
  13947.  
  13948.  This clause is arranged with headings in the same order as all the
  13949.  utility descriptions.  It is a collection of related and unrelated
  13950.  information concerning:
  13951.  
  13952.      (1)  The default actions of utilities.
  13953.  
  13954.      (2)  The meanings of notations used in the standard that are specific
  13955.           to individual utility subclauses.
  13956.  
  13957.  Although this material may seem out of place in Section 2, it is
  13958.  important that this information appear before any of the utilities to be
  13959.  described later.  Unfortunately, since the utilities are split into
  13960.  multiple major sections (chapters), this information could not be placed
  13961.  into any one of those sections without confusing cross references.
  13962.  
  13963.  END_RATIONALE
  13964.  
  13965.  
  13966.  2.11.1  Synopsis
  13967.  
  13968.  The Synopsis subclause summarizes the syntax of the calling sequence for
  13969.  the utility, including options, option-arguments, and operands.
  13970.  Standards for utility naming are described in 2.10.2; for describing the
  13971.  utility's arguments in 2.10.1.
  13972.  
  13973.  
  13974.  2.11.2  Description
  13975.  
  13976.  The Description subclause describes the actions of the utility.  If the
  13977.  utility has a very complex set of subcommands or its own procedural
  13978.  language, an Extended Description subclause is also provided.  Most
  13979.  explanations of optional functionality are omitted here, as they are
  13980.  usually explained in the Options subclause.
  13981.  
  13982.  
  13983.                Copyright c 1991 IEEE.  All rights reserved.
  13984.       This is an unapproved IEEE Standards Draft, subject to change.
  13985.  
  13986.  
  13987.  
  13988.  
  13989.  
  13990.  182                                2 Terminology and General Requirements
  13991.  
  13992.  
  13993.  
  13994.  
  13995.  
  13996.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  13997.  
  13998.  Some utilities in this standard are described in terms of equivalent
  13999.  POSIX.1 {8} functionality.  As explained in 1.1, a fully conforming
  14000.  POSIX.1 {8} base is not a prerequisite for this standard.  When specific
  14001.  functions are cited, the underlying operating system shall provide
  14002.  equivalent functionality and all side effects associated with successful
  14003.  execution of the function.  The treatment of errors and intermediate
  14004.  results from the individual functions cited are generally not specified
  14005.  by this standard.  See the utility's Exit Status and Consequences of
  14006.  Errors subclauses for all actions associated with errors encountered by
  14007.  the utility.
  14008.  
  14009.  
  14010.  2.11.3  Options
  14011.  
  14012.  The Options subclause describes the utility options and option-arguments,
  14013.  and how they modify the actions of the utility.  Standard utilities that
  14014.  have options either fully comply with the 2.10.2 or describe all
  14015.  deviations.  Apparent disagreements between functionality descriptions in
  14016.  the Options and Description (or Extended Description) subclauses are
  14017.  always resolved in favor of the Options subclause.
  14018.  
  14019.  Each Options subclause that uses the phrase ``The ... utility shall
  14020.  conform to the utility argument syntax guidelines ...'' refers only to
  14021.  the use of the utility as specified by this standard; implementation
  14022.  extensions should also conform to the guidelines, but may allow
  14023.  exceptions for historical practice.
  14024.  
  14025.  Unless otherwise stated in the utility description, when given an option
  14026.  unrecognized by the implementation, or when a required option-argument is
  14027.  not provided, standard utilities shall issue a diagnostic message to
  14028.  standard error and exit with a nonzero exit status.
  14029.  
  14030.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14031.  that the implementation need not support any options.  Standard utilities
  14032.  that do not accept options, but that do accept operands, shall recognize
  14033.  "--" as a first argument to be discarded.
  14034.  
  14035.  BEGIN_RATIONALE
  14036.  
  14037.  
  14038.  2.11.3.1  Options Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  14039.  
  14040.  Although it has not always been possible, the working group has tried to
  14041.  avoid repeating information and therefore reduced the risk that the
  14042.  duplicate explanations are somehow modified to be out of sync.
  14043.  
  14044.  The requirement for recognizing -- is because portable applications need
  14045.  a way to shield their operands from any arbitrary options that the
  14046.  implementation may provide as an extension.  For example, if the standard
  14047.  utility foo is listed as taking no options, and the application needed to
  14048.  
  14049.                Copyright c 1991 IEEE.  All rights reserved.
  14050.       This is an unapproved IEEE Standards Draft, subject to change.
  14051.  
  14052.  
  14053.  
  14054.  
  14055.  
  14056.  2.11 Utility Description Defaults                                     183
  14057.  
  14058.  
  14059.  
  14060.  
  14061.  
  14062.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14063.  
  14064.  give it a pathname with a leading hyphen, it could safely do it as:
  14065.  
  14066.        foo -- -myfile
  14067.  
  14068.  and avoid any problems with -m used as an extension.
  14069.  
  14070.  END_RATIONALE
  14071.  
  14072.  
  14073.  2.11.4  Operands
  14074.  
  14075.  The Operands subclause describes the utility operands, and how they
  14076.  affect the actions of the utility.  Apparent disagreements between
  14077.  functionality descriptions in the Operands and Description (or Extended
  14078.  Description) subclauses are always resolved in favor of the Operands
  14079.  subclause.
  14080.  
  14081.  If an operand naming a file can be specified as -, which means to use the
  14082.  standard input instead of a named file, this shall be explicitly stated
  14083.  in this subclause.  Unless otherwise stated, the use of multiple
  14084.  instances of - to mean standard input in a single command produces
  14085.  unspecified results.
  14086.  
  14087.  Unless otherwise stated, the standard utilities that accept operands
  14088.  shall process those operands in the order specified in the command line.
  14089.  
  14090.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14091.  that the implementation need not support any operands.
  14092.  
  14093.  BEGIN_RATIONALE
  14094.  
  14095.  
  14096.  2.11.4.1  Operands Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  14097.  
  14098.  This usage of - is never shown in the Synopsis.  Similarly, this usage of
  14099.  -- is never shown.
  14100.  
  14101.  The requirement for processing operands in command line order is to avoid
  14102.  a ``WeirdNIX'' utility that might choose to sort the input files
  14103.  alphabetically, by size, or by directory order.  Although this might be
  14104.  acceptable for some utilities, in general the programmer has a right to
  14105.  know exactly what order will be chosen.
  14106.  
  14107.  Some of the standard utilities take multiple _f_i_l_e operands and act as if
  14108.  they were processing the concatenation of those files.  For example,
  14109.  
  14110.        asa file1 file2          and          cat file1 file2 | asa
  14111.  
  14112.  have similar results when questions of file access, errors, and
  14113.  performance are ignored.  Other utilities, such as grep or wc, have
  14114.  
  14115.                Copyright c 1991 IEEE.  All rights reserved.
  14116.       This is an unapproved IEEE Standards Draft, subject to change.
  14117.  
  14118.  
  14119.  
  14120.  
  14121.  
  14122.  184                                2 Terminology and General Requirements
  14123.  
  14124.  
  14125.  
  14126.  
  14127.  
  14128.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14129.  
  14130.  completely different results in these two cases.  This latter type of
  14131.  utility is always identified in its Description or Operands subclauses,
  14132.  whereas the former is not.  Although it might be possible to create a
  14133.  general assertion about the former case, the following points must be
  14134.  addressed:
  14135.  
  14136.      - Access times for the files might be different in the operand case
  14137.        versus the cat case.
  14138.  
  14139.      - The utility may have error messages that are cognizant of the input
  14140.        file name and this added value should not be suppressed.  (As an
  14141.        example, awk sets a variable with the file name at each file
  14142.        boundary.)
  14143.  
  14144.  END_RATIONALE
  14145.  
  14146.  
  14147.  2.11.5  External Influences
  14148.  
  14149.  The External Influences subclause describes all input data that is
  14150.  specified by the invoker, data received from the environment, and other
  14151.  files or databases that may be used by the utility.  There are four
  14152.  subclauses that contain all the substantive information about external
  14153.  influences; because of this, this level of header is always left blank.
  14154.  
  14155.  Certain of the standard utilities describe how they can invoke other
  14156.  utilities or applications, such as by passing a command string to the
  14157.  command interpreter.  The external requirements of such invoked utilities
  14158.  are not described in the subclause concerning the standard utility that
  14159.  invokes them.
  14160.  
  14161.  
  14162.  2.11.5.1  Standard Input
  14163.  
  14164.  The Standard Input subclause describes the standard input of the utility.
  14165.  This subclause is frequently merely a reference to the following
  14166.  subclause, because many utilities treat standard input and input files in
  14167.  the same manner.  Unless otherwise stated, all restrictions described in
  14168.  Input Files apply to this subclause as well.
  14169.  
  14170.  Use of a terminal for standard input may cause any of the standard
  14171.  utilities that read standard input to stop when used in the background.
  14172.  For this reason, applications should not use interactive features in
  14173.  scripts to be placed in the background.
  14174.  
  14175.  The specified standard input format of the standard utilities shall not
  14176.  depend on the existence or value of the environment variables defined in
  14177.  this standard, except as provided by this standard.
  14178.  
  14179.  
  14180.  
  14181.                Copyright c 1991 IEEE.  All rights reserved.
  14182.       This is an unapproved IEEE Standards Draft, subject to change.
  14183.  
  14184.  
  14185.  
  14186.  
  14187.  
  14188.  2.11 Utility Description Defaults                                     185
  14189.  
  14190.  
  14191.  
  14192.  
  14193.  
  14194.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14195.  
  14196.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14197.  that the standard input shall not be read when the utility is used as
  14198.  described by this standard.
  14199.  
  14200.  BEGIN_RATIONALE
  14201.  
  14202.  2.11.5.1.1  Standard Input Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14203.              _P_1_0_0_3._2)
  14204.  
  14205.  This subclause was globally renamed from Standard Input Format in
  14206.  previous drafts to better reflect its role in describing the existence
  14207.  and usage of the file, in addition to its format.
  14208.  
  14209.  END_RATIONALE
  14210.  
  14211.  
  14212.  2.11.5.2  Input Files
  14213.  
  14214.  The Input Files subclause describes the files, other than the standard
  14215.  input, used as input by the utility.  It includes files named as operands
  14216.  and option-arguments as well as other files that are referred to, such as
  14217.  startup/initialization files, databases, etc.  Commonly-used files are
  14218.  generally described in one place and cross-referenced by other utilities.
  14219.  
  14220.  Some of the standard utilities, such as filters, process input files a
  14221.  line or a block at a time and have no restrictions on the maximum input
  14222.  file size.  Some utilities may have size limitations that are not as
  14223.  obvious as file space or memory limitations.  Such limitations should
  14224.  reflect resource limitations of some sort, not arbitrary limits set by
  14225.  implementors.  Implementations shall define in the conformance
  14226.  documentation those utilities that are limited by constraints other than
  14227.  file system space, available memory, and other limits specifically cited
  14228.  by this standard, and identify what the constraint is, and indicate a way
  14229.  of estimating when the constraint would be reached.  Similarly, some
  14230.  utilities descend the directory tree (recursively).  Implementations
  14231.  shall also document any limits that they may have in descending the
  14232.  directory tree that are beyond limits cited by this standard.
  14233.  
  14234.  When a standard utility reads a seekable input file and terminates         1
  14235.  without an error before it reaches end-of-file, the utility shall ensure   1
  14236.  that the file offset in the open file description is properly positioned   1
  14237.  just past the last byte processed by the utility.  For files that are not  1
  14238.  seekable, the state of the file offset in the open file description for    1
  14239.  that file is unspecified.                                                  1
  14240.  
  14241.  When an input file is described as a _t_e_x_t _f_i_l_e, the utility produces
  14242.  undefined results if given input that is not from a text file, unless
  14243.  otherwise stated.  Some utilities (e.g., make, read, sh, etc.) allow for
  14244.  continued input lines using an escaped <newline> convention; unless
  14245.  otherwise stated, the utility need not be able to accumulate more than
  14246.  
  14247.                Copyright c 1991 IEEE.  All rights reserved.
  14248.       This is an unapproved IEEE Standards Draft, subject to change.
  14249.  
  14250.  
  14251.  
  14252.  
  14253.  
  14254.  186                                2 Terminology and General Requirements
  14255.  
  14256.  
  14257.  
  14258.  
  14259.  
  14260.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14261.  
  14262.  {LINE_MAX} bytes from a set of multiple, continued input lines.  If a
  14263.  utility using the escaped <newline> convention detects an end-of-file
  14264.  condition immediately after an escaped <newline>, the results are
  14265.  unspecified.
  14266.  
  14267.  Record formats are described in a notation similar to that used by the C
  14268.  language function, _p_r_i_n_t_f().  See 2.12 for a description of this
  14269.  notation.
  14270.  
  14271.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14272.  that no input files are required to be supplied when the utility is used
  14273.  as described by this standard.
  14274.  
  14275.  BEGIN_RATIONALE
  14276.  
  14277.  2.11.5.2.1  Input Files Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14278.              _P_1_0_0_3._2)
  14279.  
  14280.  This subclause was globally renamed from Input File Formats in previous
  14281.  drafts to better reflect its role in describing the existence and usage
  14282.  of the files, in addition to their format.
  14283.  
  14284.  The description of file offsets answers the question:  Are the following   1
  14285.  three commands equivalent?                                                 1
  14286.  
  14287.        tail -n +2 file                                                      1
  14288.        (sed -n 1q; cat) < file                                              1
  14289.        cat file | (sed -n 1q; cat)                                          1
  14290.  
  14291.  The answer is that a conforming application cannot assume they are         1
  14292.  equivalent.  The second command is equivalent to the first only when the   1
  14293.  file is seekable.  In the third command, if the file offset in the open    1
  14294.  file description were not unspecified, sed would have to be implemented    1
  14295.  so that it read from the pipe one byte at a time or it would have to       1
  14296.  employ some method to seek backwards on the pipe.  Such functionality is   1
  14297.  not defined currently in POSIX.1 {8} and does not exist on all historical  1
  14298.  systems.  Other utilities, such as head, read, and sh, have similar        1
  14299.  properties, so the restriction is described globally in this clause.  A    1
  14300.  future revision to this standard may require that the standard utilities   1
  14301.  leave the file offset in a consistent state for pipes as well as regular   1
  14302.  files.                                                                     1
  14303.  
  14304.  The description of conformance documentation about file sizes follows
  14305.  many changes of direction by the working group.  Originally, there
  14306.  appeared a limit, {ED_FILE_MAX}, that hoped to impose a minimum file size
  14307.  on ed, which has been historically limited to relatively small files.
  14308.  This received objections from various members who said that such a limit
  14309.  merely invited sloppy programming; there should be no limits to a
  14310.  ``well-written'' ed.  Thus, Draft 8 removed the limit and inserted
  14311.  
  14312.  
  14313.                Copyright c 1991 IEEE.  All rights reserved.
  14314.       This is an unapproved IEEE Standards Draft, subject to change.
  14315.  
  14316.  
  14317.  
  14318.  
  14319.  
  14320.  2.11 Utility Description Defaults                                     187
  14321.  
  14322.  
  14323.  
  14324.  
  14325.  
  14326.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14327.  
  14328.  rationale that this meant ed would have to process files of virtually
  14329.  unlimited size.  (Surprisingly, no objections or comments were received
  14330.  about that sentence.)  However, in discussing the matter with
  14331.  representatives of POSIX.3, it turned out that omitting the limit meant
  14332.  that a corresponding test assertion would also be omitted and no test
  14333.  suite could legitimately stress ed with large files.  It quickly became
  14334.  clear that restrictions applied to other utilities as well and a solution
  14335.  was needed.
  14336.  
  14337.  It is not possible for this standard to judge which utilities are in the
  14338.  category with arbitrary file size limits; this would impose too much on
  14339.  implementors.  Therefore, the burden is placed on implementors to
  14340.  publicly document any limitations and the resulting pressure in the
  14341.  marketplace should keep most implementations adequate for most portable
  14342.  applications.  Typically, larger systems would have larger limits than
  14343.  smaller systems, but since price typically follows function, the user can
  14344.  select a machine that handles his/her problems reasonably given such
  14345.  information.  The working group considered adding a limit in 2.13.1 for
  14346.  every file-oriented utility, but felt these limits would not actually be
  14347.  used by real applications and would reduce consensus.  This is
  14348.  particularly true for utilities, such as possibly awk or yacc, that might
  14349.  have rather complex limits not directly related to the actual file size.
  14350.  
  14351.  The definition of _t_e_x_t _f_i_l_e (see 2.2.2.151) is strictly enforced for
  14352.  input to the standard utilities; very few of them list exceptions to the
  14353.  undefined results called for here.  (Of course, ``undefined'' here does
  14354.  not mean that existing implementations necessarily have to change to
  14355.  start indicating error conditions.  Conforming applications cannot rely
  14356.  on implementations succeeding or failing when nontext files are used.)
  14357.  
  14358.  The utilities that allow line continuation are generally those that
  14359.  accept input languages, rather than pure data.  It would be unusual for
  14360.  an input line of this type to exceed {LINE_MAX} bytes and unreasonable to
  14361.  require that the implementation allow unlimited accumulation of multiple
  14362.  lines, each of which could reach {LINE_MAX}.  Thus, for a portable
  14363.  application the total of all the continued lines in a set cannot exceed
  14364.  {LINE_MAX}.
  14365.  
  14366.  The format description is intended to be sufficiently rigorous to allow
  14367.  other applications to generate these input files.  However, since
  14368.  <blank>s can legitimately be included in some of the fields described by
  14369.  the standard utilities, particularly in locales other than the POSIX
  14370.  Locale, this intent is not always realized.
  14371.  
  14372.  END_RATIONALE
  14373.  
  14374.  
  14375.  
  14376.  
  14377.  
  14378.  
  14379.                Copyright c 1991 IEEE.  All rights reserved.
  14380.       This is an unapproved IEEE Standards Draft, subject to change.
  14381.  
  14382.  
  14383.  
  14384.  
  14385.  
  14386.  188                                2 Terminology and General Requirements
  14387.  
  14388.  
  14389.  
  14390.  
  14391.  
  14392.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14393.  
  14394.  2.11.5.3  Environment Variables
  14395.  
  14396.  The Environment Variables subclause lists what variables affect the
  14397.  utility's execution.
  14398.  
  14399.  The entire manner in which environment variables described in this
  14400.  standard affect the behavior of each utility is described in the
  14401.  Environment Variables subclause for that utility, in conjunction with the
  14402.  global effects of the LANG and LC_ALL environment variables described in
  14403.  2.6.  The existence or value of environment variables described in this
  14404.  standard shall not otherwise affect the specified behavior of the
  14405.  standard utilities.  Any effects of the existence or value of environment
  14406.  variables not described by this standard upon the standard utilities are
  14407.  unspecified.
  14408.  
  14409.  For those standard utilities that use environment variables as a means
  14410.  for selecting a utility to execute (such as CC in make), the string
  14411.  provided to the utility shall be subjected to the path search described
  14412.  for PATH in 2.6.
  14413.  
  14414.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14415.  that the behavior of the utility is not directly affected by environment
  14416.  variables described by this standard when the utility is used as
  14417.  described by this standard.
  14418.  
  14419.  BEGIN_RATIONALE
  14420.  
  14421.  2.11.5.3.1  Environment Variables Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  14422.              _p_a_r_t _o_f _P_1_0_0_3._2)
  14423.  
  14424.  The global default text about the PATH search is overkill in this version
  14425.  of POSIX.2 (prior to the UPE) because only one of the standard utilities
  14426.  specifies variables in this way--make's $(CC), $(LEX), etc.  It is
  14427.  described here mostly in anticipation of its heavier usage in POSIX.2a.
  14428.  The description of PATH indicates separately that names including slashes
  14429.  do not apply, so they do not apply here either.
  14430.  
  14431.  END_RATIONALE
  14432.  
  14433.  
  14434.  2.11.5.4  Asynchronous Events
  14435.  
  14436.  The Asynchronous Events subclause lists how the utility reacts to such
  14437.  events as signals and what signals are caught.
  14438.  
  14439.  Default Behavior:  When this subclause is listed as ``Default,'' or it
  14440.  refers to ``the standard action for all other signals; see 2.11.5.4,'' it
  14441.  means that the action taken as a result of the signal shall be one of the
  14442.  following:
  14443.  
  14444.  
  14445.                Copyright c 1991 IEEE.  All rights reserved.
  14446.       This is an unapproved IEEE Standards Draft, subject to change.
  14447.  
  14448.  
  14449.  
  14450.  
  14451.  
  14452.  2.11 Utility Description Defaults                                     189
  14453.  
  14454.  
  14455.  
  14456.  
  14457.  
  14458.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14459.  
  14460.      (1)  The action is that inherited from the parent according to the
  14461.           rules of inheritance of signal actions defined in POSIX.1 {8}
  14462.           (see 2.9.1), or
  14463.  
  14464.      (2)  When no action has been taken to change the default, the default
  14465.           action is that specified by POSIX.1 {8}, or
  14466.  
  14467.      (3)  The result of the utility's execution is as if default actions
  14468.           had been taken.
  14469.  
  14470.  BEGIN_RATIONALE
  14471.  
  14472.  2.11.5.4.1  Asynchronous Events Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  14473.              _o_f _P_1_0_0_3._2)
  14474.  
  14475.  Because there is no language prohibiting it, a utility is permitted to
  14476.  catch a signal, perform some additional processing (such as deleting
  14477.  temporary files), restore the default signal action (or action inherited
  14478.  from the parent process) and resignal itself.
  14479.  
  14480.  END_RATIONALE
  14481.  
  14482.  
  14483.  2.11.6  External Effects
  14484.  
  14485.  The External Effects subclause describes the effects of the utility on
  14486.  the operational environment, including the file system.  There are three
  14487.  subclauses that contain all the substantive information about external
  14488.  effects; because of this, this level of header is usually left blank.
  14489.  
  14490.  Certain of the standard utilities describe how they can invoke other
  14491.  utilities or applications, such as by passing a command string to the
  14492.  command interpreter.  The external effects of such invoked utilities are
  14493.  not described in the subclause concerning the standard utility that
  14494.  invokes them.
  14495.  
  14496.  
  14497.  2.11.6.1  Standard Output
  14498.  
  14499.  The Standard Output subclause describes the standard output of the
  14500.  utility.  This subclause is frequently merely a reference to the
  14501.  following subclause, Output Files, because many utilities treat standard
  14502.  output and output files in the same manner.
  14503.  
  14504.  Use of a terminal for standard output may cause any of the standard
  14505.  utilities that write standard output to stop when used in the background.
  14506.  For this reason, applications should not use interactive features in
  14507.  scripts to be placed in the background.
  14508.  
  14509.  
  14510.  
  14511.                Copyright c 1991 IEEE.  All rights reserved.
  14512.       This is an unapproved IEEE Standards Draft, subject to change.
  14513.  
  14514.  
  14515.  
  14516.  
  14517.  
  14518.  190                                2 Terminology and General Requirements
  14519.  
  14520.  
  14521.  
  14522.  
  14523.  
  14524.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14525.  
  14526.  Record formats are described in a notation similar to that used by the C
  14527.  language function, _p_r_i_n_t_f().  See 2.12 for a description of this
  14528.  notation.
  14529.  
  14530.  The specified standard output of the standard utilities shall not depend
  14531.  on the existence or value of the environment variables defined in this
  14532.  standard, except as provided by this standard.
  14533.  
  14534.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14535.  that the standard output shall not be written when the utility is used as
  14536.  described by this standard.
  14537.  
  14538.  BEGIN_RATIONALE
  14539.  
  14540.  2.11.6.1.1  Standard Output Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14541.              _P_1_0_0_3._2)
  14542.  
  14543.  This subclause was globally renamed from Standard Output Format in
  14544.  previous drafts to better reflect its role in describing the existence
  14545.  and usage of the file, in addition to its format.
  14546.  
  14547.  The format description is intended to be sufficiently rigorous to allow
  14548.  post-processing of output by other programs, particularly by an awk or
  14549.  lex parser.
  14550.  
  14551.  END_RATIONALE
  14552.  
  14553.  
  14554.  2.11.6.2  Standard Error
  14555.  
  14556.  The Standard Error subclause describes the standard error output of the
  14557.  utility.  Only those messages that are purposely sent by the utility are
  14558.  described.
  14559.  
  14560.  Use of a terminal for standard error may cause any of the standard
  14561.  utilities that write standard error output to stop when used in the
  14562.  background.  For this reason, applications should not use interactive
  14563.  features in scripts to be placed in the background.
  14564.  
  14565.  The format of diagnostic messages for most utilities is unspecified, but
  14566.  the language and cultural conventions of diagnostic and informative
  14567.  messages whose format is unspecified by this standard should be affected
  14568.  by the setting of LC_MESSAGES.
  14569.  
  14570.  The specified standard error output of standard utilities shall not
  14571.  depend on the existence or value of the environment variables defined in
  14572.  this standard, except as provided by this standard.
  14573.  
  14574.  
  14575.  
  14576.  
  14577.                Copyright c 1991 IEEE.  All rights reserved.
  14578.       This is an unapproved IEEE Standards Draft, subject to change.
  14579.  
  14580.  
  14581.  
  14582.  
  14583.  
  14584.  2.11 Utility Description Defaults                                     191
  14585.  
  14586.  
  14587.  
  14588.  
  14589.  
  14590.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14591.  
  14592.  Default Behavior:  When this subclause is listed as ``Used only for
  14593.  diagnostic messages,'' it means that, unless otherwise stated, the
  14594.  diagnostic messages shall be sent to the standard error only when the
  14595.  exit status is nonzero and the utility is used as described by this
  14596.  standard.
  14597.  
  14598.  When this subclause is listed as ``None,'' it means that the standard
  14599.  error shall not be used when the utility is used as described in this
  14600.  standard.
  14601.  
  14602.  BEGIN_RATIONALE
  14603.  
  14604.  2.11.6.2.1  Standard Error Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14605.              _P_1_0_0_3._2)
  14606.  
  14607.  This subclause was globally renamed from Standard Error Format in
  14608.  previous drafts to better reflect its role in describing the existence
  14609.  and usage of the file, in addition to its format.
  14610.  
  14611.  This subclause does not describe error messages that refer to incorrect
  14612.  operation of the utility.  Consider a utility that processes program
  14613.  source code as its input.  This subclause is used to describe messages
  14614.  produced by a correctly operating utility that encounters an error in the
  14615.  program source code on which it is processing.  However, a message
  14616.  indicating that the utility had insufficient memory in which to operate
  14617.  would not be described.
  14618.  
  14619.  Some compilers have traditionally produced warning messages without
  14620.  returning a nonzero exit status; these are specifically noted in their
  14621.  subclauses.  Other utilities are expected to remain absolutely quiet on
  14622.  the standard error if they want to return zero, unless the implementation
  14623.  provides some sort of extension to increase the verbosity or debugging
  14624.  level.
  14625.  
  14626.  The format descriptions are intended to be sufficiently rigorous to allow
  14627.  post-processing of output by other programs.
  14628.  
  14629.  END_RATIONALE
  14630.  
  14631.  
  14632.  2.11.6.3  Output Files
  14633.  
  14634.  The Output Files subclause describes the files created or modified by the
  14635.  utility.  Temporary or system files that are created for internal usage
  14636.  by this utility or other parts of the implementation (spool, log, audit
  14637.  files, etc.)  are not described in this, or any, subclause.  The
  14638.  utilities creating such files and the names of such files are
  14639.  unspecified.  If applications are written to use temporary or
  14640.  intermediate files, they should use the TMPDIR environment variable, if
  14641.  it is set and represents an accessible directory, to select the location   1
  14642.  
  14643.                Copyright c 1991 IEEE.  All rights reserved.
  14644.       This is an unapproved IEEE Standards Draft, subject to change.
  14645.  
  14646.  
  14647.  
  14648.  
  14649.  
  14650.  192                                2 Terminology and General Requirements
  14651.  
  14652.  
  14653.  
  14654.  
  14655.  
  14656.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14657.  
  14658.  of temporary files.                                                        1
  14659.  
  14660.  Implementations shall ensure that temporary files, when used by the
  14661.  standard utilities, are named so that different utilities or multiple
  14662.  instances of the same utility can operate simultaneously without regard
  14663.  to their working directories, or any other process characteristic other
  14664.  than process ID.  There are two exceptions to this requirement:
  14665.  
  14666.      (1)  Resources for temporary files other than the namespace (for
  14667.           example, disk space, available directory entries, or number of
  14668.           processes allowed) are not guaranteed.
  14669.  
  14670.      (2)  Certain standard utilities generate output files that are
  14671.           intended as input for other utilities, (for example, lex
  14672.           generates lex.yy.c) and these cannot have unique names.  These
  14673.           cases are explicitly identified in the descriptions of the
  14674.           respective utilities.
  14675.  
  14676.  Any temporary files created by the implementation shall be removed by the
  14677.  implementation upon a utility's successful exit, exit because of errors,
  14678.  or before termination by any of the SIGHUP, SIGINT, or SIGTERM signals,
  14679.  unless specified otherwise by the utility description.
  14680.  
  14681.  Record formats are described in a notation similar to that used by the C
  14682.  language function, _p_r_i_n_t_f().  See 2.12 for a description of this
  14683.  notation.
  14684.  
  14685.  Default Behavior:  When this subclause is listed as ``None,'' it means
  14686.  that no files are created or modified as a consequence of direct action
  14687.  on the part of the utility when the utility is used as described by this
  14688.  standard.  However, the utility may create or modify system files, such
  14689.  as log files, that are outside of the utility's normal execution
  14690.  environment.
  14691.  
  14692.  BEGIN_RATIONALE
  14693.  
  14694.  2.11.6.3.1  Output Files Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14695.              _P_1_0_0_3._2)
  14696.  
  14697.  This subclause was globally renamed from Output File Formats in previous
  14698.  drafts to better reflect its role in describing the existence and usage
  14699.  of the files, in addition to their format.
  14700.  
  14701.  The format description is intended to be sufficiently rigorous to allow
  14702.  post-processing of output by other programs, particularly by an awk or
  14703.  lex parser.
  14704.  
  14705.  Receipt of the SIGQUIT signal should generally cause termination (unless
  14706.  in some debugging mode) that would bypass any attempted recovery actions.
  14707.  
  14708.  
  14709.                Copyright c 1991 IEEE.  All rights reserved.
  14710.       This is an unapproved IEEE Standards Draft, subject to change.
  14711.  
  14712.  
  14713.  
  14714.  
  14715.  
  14716.  2.11 Utility Description Defaults                                     193
  14717.  
  14718.  
  14719.  
  14720.  
  14721.  
  14722.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14723.  
  14724.  END_RATIONALE
  14725.  
  14726.  
  14727.  2.11.7  Extended Description
  14728.  
  14729.  The Extended Description subclause provides a place for describing the
  14730.  actions of very complicated utilities, such as text editors or language
  14731.  processors, which typically have elaborate command languages.
  14732.  
  14733.  Default Behavior:  When this subclause is listed as ``None,'' no further
  14734.  description is necessary.
  14735.  
  14736.  
  14737.  2.11.8  Exit Status
  14738.  
  14739.  The Exit Status subclause describes the values the utility shall return
  14740.  to the calling program, or shell, and the conditions that cause these
  14741.  values to be returned.  Usually, utilities return zero for successful
  14742.  completion and values greater than zero for various error conditions.  If
  14743.  specific numeric values are listed in this subclause, conforming
  14744.  implementations shall use those values for the errors described.  In some
  14745.  cases, status values are listed more loosely, such as ``>0.''  A Strictly
  14746.  Conforming POSIX.2 Application shall not rely on any specific value in
  14747.  the range shown and shall be prepared to receive any value in the range.
  14748.  
  14749.  Unspecified error conditions may be represented by specific values not
  14750.  listed in the standard.
  14751.  
  14752.  BEGIN_RATIONALE
  14753.  
  14754.  
  14755.  2.11.8.1  Exit Status Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  14756.            _P_1_0_0_3._2)
  14757.  
  14758.  Note the additional discussion of exit status values in 3.8.2.  It         1
  14759.  describes requirements for returning exit values > 125.                    1
  14760.  
  14761.  A utility may list zero as a successful return, 1 as a failure for a
  14762.  specific reason, and >1 as ``an error occurred.''  In this case,
  14763.  unspecified conditions may cause a 2 or 3, or other value, to be
  14764.  returned.  A Strictly Conforming POSIX.2 Application should be written so
  14765.  that it tests for successful exit status values (zero in this case),
  14766.  rather than relying upon the single specific error value listed in the
  14767.  standard.  In that way, it will have maximum portability, even on
  14768.  implementations with extensions.
  14769.  
  14770.  The working group is aware that the general nonenumeration of errors
  14771.  makes it difficult to write test suites that test the _i_n_c_o_r_r_e_c_t operation
  14772.  of utilities.  There are some historical implementations that have
  14773.  expended effort to provide detailed status messages and a helpful
  14774.  
  14775.                Copyright c 1991 IEEE.  All rights reserved.
  14776.       This is an unapproved IEEE Standards Draft, subject to change.
  14777.  
  14778.  
  14779.  
  14780.  
  14781.  
  14782.  194                                2 Terminology and General Requirements
  14783.  
  14784.  
  14785.  
  14786.  
  14787.  
  14788.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14789.  
  14790.  environment to bypass or explain errors, such as prompting, retrying, or
  14791.  ignoring unimportant syntax errors; other implementations have not.
  14792.  Since there is no realistic way to mandate system behavior in cases of
  14793.  undefined application actions or system problems--in a manner acceptable
  14794.  to all cultures and environments--attention has been limited to the
  14795.  correct operation of utilities by the conforming application.
  14796.  Furthermore, the portable application does not need detailed information
  14797.  concerning errors that it caused through incorrect usage or that it
  14798.  cannot correct anyway.  The high degree of competition in the emerging
  14799.  POSIX marketplace should ensure that users requiring friendly, resilient
  14800.  environments will be able to purchase such without detailed specification
  14801.  in this standard.
  14802.  
  14803.  There is no description of defaults for this subclause because all of the
  14804.  standard utilities specify something (or explicitly state
  14805.  ``Unspecified'') for Exit Status.
  14806.  
  14807.  END_RATIONALE
  14808.  
  14809.  
  14810.  2.11.9  Consequences of Errors
  14811.  
  14812.  The Consequences of Errors subclause describes the effects on the
  14813.  environment, file systems, process state, etc., when error conditions
  14814.  occur.  It does not describe error messages produced or exit status
  14815.  values used.
  14816.  
  14817.  The many reasons for failure of a utility are generally not specified by
  14818.  the utility descriptions.  Utilities may terminate prematurely if they
  14819.  encounter:  invalid usage of options, arguments, or environment
  14820.  variables; invalid usage of the complex syntaxes expressed in Extended
  14821.  Description subclauses; difficulties accessing, creating, reading, or
  14822.  writing files; or, difficulties associated with the privileges of the
  14823.  process.
  14824.  
  14825.  The following shall apply to each utility, unless otherwise stated:
  14826.  
  14827.      - If the requested action cannot be performed on an operand
  14828.        representing a file, directory, user, process, etc., the utility
  14829.        shall issue a diagnostic message to standard error and continue
  14830.        processing the next operand in sequence, but the final exit status
  14831.        shall be returned as nonzero.
  14832.  
  14833.      - If the requested action characterized by an option or option-
  14834.        argument cannot be performed, the utility shall issue a diagnostic
  14835.        message to standard error and the exit status returned shall be
  14836.        nonzero.
  14837.  
  14838.  
  14839.  
  14840.  
  14841.                Copyright c 1991 IEEE.  All rights reserved.
  14842.       This is an unapproved IEEE Standards Draft, subject to change.
  14843.  
  14844.  
  14845.  
  14846.  
  14847.  
  14848.  2.11 Utility Description Defaults                                     195
  14849.  
  14850.  
  14851.  
  14852.  
  14853.  
  14854.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14855.  
  14856.      - When an unrecoverable error condition is encountered, the utility
  14857.        shall exit with a nonzero exit status.
  14858.  
  14859.      - A diagnostic message shall be written to standard error whenever an
  14860.        error condition occurs.
  14861.  
  14862.  Default Behavior:  When this subclause is listed as ``Default,'' it means
  14863.  that any changes to the environment are unspecified.
  14864.  
  14865.  BEGIN_RATIONALE
  14866.  
  14867.  
  14868.  2.11.9.1  Consequences of Errors Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  14869.            _o_f _P_1_0_0_3._2)
  14870.  
  14871.  When a utility encounters an error condition several actions are
  14872.  possible, depending on the severity of the error and the state of the
  14873.  utility.  Included in the possible actions of various utilities are:
  14874.  deletion of temporary or intermediate work files; deletion of incomplete
  14875.  files; validity checking of the file system or directory.
  14876.  
  14877.  In Draft 9, most of the Consequences of Errors subclauses were changed to
  14878.  ``Default.''  This is due to the more elaborate description of the
  14879.  default case now carried in this subclause and the fact that most of the
  14880.  standard utilities actually use that default.
  14881.  
  14882.  END_RATIONALE
  14883.  
  14884.  BEGIN_RATIONALE
  14885.  
  14886.  
  14887.  2.11.10  Rationale
  14888.  
  14889.  This subclause provides historical perspective and justification of
  14890.  working group actions concerning the utility.
  14891.  
  14892.  _E_x_a_m_p_l_e_s_,__U_s_a_g_e
  14893.  
  14894.  This subclause provides examples and usage of the utility.  In some cases
  14895.  certain characters are interpreted as special characters to the shell.
  14896.  In the rest of the standard, these characters are shown without escape
  14897.  characters or quoting (see 3.2).  In all examples, however, quoting has
  14898.  been used, showing how sample commands (utility names combined with
  14899.  arguments) could be passed correctly to a shell (see sh in 4.56) or as a
  14900.  string to the _s_y_s_t_e_m() function.
  14901.  
  14902.  
  14903.  
  14904.  
  14905.  
  14906.  
  14907.                Copyright c 1991 IEEE.  All rights reserved.
  14908.       This is an unapproved IEEE Standards Draft, subject to change.
  14909.  
  14910.  
  14911.  
  14912.  
  14913.  
  14914.  196                                2 Terminology and General Requirements
  14915.  
  14916.  
  14917.  
  14918.  
  14919.  
  14920.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  14921.  
  14922.  _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e
  14923.  
  14924.  This subclause provides historical perspective for decisions that were
  14925.  made.
  14926.  
  14927.  _U_n_r_e_s_o_l_v_e_d__O_b_j_e_c_t_i_o_n_s
  14928.  
  14929.  These subclauses were removed from Draft 10.  The Unresolved Objections
  14930.  are maintained in a separate list and do not meet ISO editing
  14931.  requirements for an informative annex.
  14932.  
  14933.  
  14934.  2.11.10.1  Rationale Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  14935.  
  14936.  The Rationale subclauses will be moved to Annex E in the final POSIX.2.
  14937.  Some of the subheadings may be collapsed in that document; in these
  14938.  drafts the working group has not always been very rigorous about what is
  14939.  a description of usage versus a history of decisions made, for example.
  14940.  The final rationale will de-emphasize the chronological aspects of
  14941.  working group decisions.
  14942.  
  14943.  END_RATIONALE
  14944.  
  14945.  
  14946.  
  14947.  
  14948.  
  14949.  
  14950.  
  14951.  
  14952.  
  14953.  
  14954.  
  14955.  
  14956.  
  14957.  
  14958.  
  14959.  
  14960.  
  14961.  
  14962.  
  14963.  
  14964.  
  14965.  
  14966.  
  14967.  
  14968.  
  14969.  
  14970.  
  14971.  
  14972.  
  14973.                Copyright c 1991 IEEE.  All rights reserved.
  14974.       This is an unapproved IEEE Standards Draft, subject to change.
  14975.  
  14976.  
  14977.  
  14978.  
  14979.  
  14980.  2.11 Utility Description Defaults                                     197
  14981.  
  14982.  
  14983.  
  14984.  
  14985.  
  14986.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  14987.  
  14988.  2.12  File Format Notation
  14989.  
  14990.  The Standard Input, Standard Output, Standard Error, Input Files, and
  14991.  Output Files subclauses of the utility descriptions, when provided, use a
  14992.  syntax to describe the data organization within the files, when that
  14993.  organization is not otherwise obvious.  The syntax is similar to that
  14994.  used by the C language _p_r_i_n_t_f() function, as described in this clause.
  14995.  When used in Standard Input or Input Files subclauses of the utility
  14996.  descriptions, this syntax describes the format that could have been used
  14997.  to write the text to be read, not a format that could be used by the C
  14998.  language _s_c_a_n_f() function to read the input file.
  14999.  
  15000.  The description of an individual record is as follows:
  15001.  
  15002.        "<_f_o_r_m_a_t>", [ <_a_r_g_1>, <_a_r_g_2>, ..., <_a_r_g_n> ]
  15003.  
  15004.  The _f_o_r_m_a_t is a character string that contains three types of objects
  15005.  defined below:
  15006.  
  15007.     _c_h_a_r_a_c_t_e_r_s  Characters that are not _e_s_c_a_p_e _s_e_q_u_e_n_c_e_s or _c_o_n_v_e_r_s_i_o_n
  15008.                 _s_p_e_c_i_f_i_c_a_t_i_o_n_s, as described below, shall be copied to the
  15009.                 output.
  15010.  
  15011.     _e_s_c_a_p_e _s_e_q_u_e_n_c_e_s
  15012.                 Represent nongraphic characters.
  15013.  
  15014.     _c_o_n_v_e_r_s_i_o_n _s_p_e_c_i_f_i_c_a_t_i_o_n_s
  15015.                 Specifies the output format of each argument.  (See
  15016.                 below.)
  15017.  
  15018.  The following characters have the following special meaning in the format
  15019.  string:
  15020.  
  15021.     " "         (An empty character position.)  One or more <blank>
  15022.                 characters.
  15023.  
  15024.     W           Exactly one <space> character.
  15025.  
  15026.  The escape-sequences in Table 2-15 depict the associated action on
  15027.  display devices capable of the action.
  15028.  
  15029.  Each conversion specification shall be introduced by the percent-sign
  15030.  character (%).  After the character %, the following shall appear in
  15031.  sequence:
  15032.  
  15033.     _f_l_a_g_s       Zero or more _f_l_a_g_s, in any order, that modify the meaning
  15034.                 of the conversion specification.
  15035.  
  15036.  
  15037.  
  15038.  
  15039.                Copyright c 1991 IEEE.  All rights reserved.
  15040.       This is an unapproved IEEE Standards Draft, subject to change.
  15041.  
  15042.  
  15043.  
  15044.  
  15045.  
  15046.  198                                2 Terminology and General Requirements
  15047.  
  15048.  
  15049.  
  15050.  
  15051.  
  15052.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15053.  
  15054.  
  15055.                       Table 2-15  -  Escape Sequences
  15056.  __________________________________________________________________________________________________________________________________________________
  15057.   Escape       Represents
  15058.  Sequence       Character                       Terminal Action
  15059.  _________________________________________________________________________
  15060.  
  15061.     \\      backslash                None.
  15062.     \a      <alert>                  Attempts to alert the user through
  15063.                                      audible or visible notification.
  15064.     \b      <backspace>              Moves the printing position to one
  15065.                                      column before the current position,
  15066.                                      unless the current position is the
  15067.                                      start of a line.
  15068.     \f      <form-feed>              Moves the printing position to the
  15069.                                      initial printing position of the next
  15070.                                      logical page.
  15071.     \n      <newline>                Moves the printing position to the
  15072.                                      start of the next line.
  15073.     \r      <carriage-return>        Moves the printing position to the
  15074.                                      start of the current line.
  15075.     \t      <tab>                    Moves the printing position to the
  15076.                                      next tab position on the current
  15077.                                      line.  If there are no more tab
  15078.                                      positions left on the line, the
  15079.                                      behavior is undefined.
  15080.     \v      <vertical tab>           Moves the printing position to the
  15081.                                      start of the next vertical tab
  15082.                                      position.  If there are no more
  15083.                                      vertical tab positions left on the
  15084.                                      page, the behavior is undefined.
  15085.  __________________________________________________________________________________________________________________________________________________
  15086.  
  15087.  
  15088.     _f_i_e_l_d _w_i_d_t_h An optional string of decimal digits to specify a minimum
  15089.                 _f_i_e_l_d _w_i_d_t_h.  For an output field, if the converted value
  15090.                 has fewer bytes than the field width, it shall be padded
  15091.                 on the left [or right, if the left-adjustment flag (-),
  15092.                 described below, has been given] to the field width.
  15093.  
  15094.     _p_r_e_c_i_s_i_o_n   Gives the minimum number of digits to appear for the d, o,
  15095.                 i, u, x, or X conversions (the field shall be padded with
  15096.                 leading zeros), the number of digits to appear after the
  15097.                 radix character for the e and f conversions, the maximum
  15098.                 number of significant digits for the g conversion; or the
  15099.                 maximum number of bytes to be written from a string in s
  15100.                 conversion.  The precision shall take the form of a period
  15101.                 (.) followed by a decimal digit string; a null digit
  15102.                 string shall be treated as zero.
  15103.  
  15104.  
  15105.                Copyright c 1991 IEEE.  All rights reserved.
  15106.       This is an unapproved IEEE Standards Draft, subject to change.
  15107.  
  15108.  
  15109.  
  15110.  
  15111.  
  15112.  2.12 File Format Notation                                             199
  15113.  
  15114.  
  15115.  
  15116.  
  15117.  
  15118.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15119.  
  15120.     _c_o_n_v_e_r_s_i_o_n _c_h_a_r_a_c_t_e_r_s
  15121.                 A conversion character (see below) that indicates the type
  15122.                 of conversion to be applied.
  15123.  
  15124.  The _f_l_a_g characters and their meanings are:
  15125.  
  15126.     -           The result of the conversion shall be left-justified
  15127.                 within the field.
  15128.  
  15129.     +           The result of a signed conversion always shall begin with
  15130.                 a sign (+ or -).
  15131.  
  15132.     <space>     If the first character of a signed conversion is not a
  15133.                 sign, a <space> shall be prefixed to the result.  This
  15134.                 means that if the <space> and + flags both appear, the
  15135.                 <space> flag shall be ignored.
  15136.  
  15137.     #           The value is to be converted to an ``alternate form.''
  15138.                 For c, d, i, u, and s conversions, the behavior is
  15139.                 undefined.  For o conversion, it shall increase the
  15140.                 precision to force the first digit of the result to be a
  15141.                 zero.  For x or X conversion, a nonzero result shall have
  15142.                 0x or 0X prefixed to it, respectively.  For e, E, f, g and
  15143.                 G conversions, the result shall always contain a radix
  15144.                 character, even if no digits follow the radix character.
  15145.                 For g and G conversions, trailing zeroes shall not be
  15146.                 removed from the result as they usually are.
  15147.  
  15148.     0           For d, i, o, u, x, X, e, E, f, g, and G conversions,
  15149.                 leading zeroes (following any indication of sign or base)
  15150.                 shall be used to pad to the field width; no space padding
  15151.                 shall be performed.  If the 0 and - flags both appear, the
  15152.                 0 flag shall be ignored.  For d, i, o, u, x, and X
  15153.                 conversions, if a precision is specified, the 0 flag shall
  15154.                 be ignored.  For other conversions, the behavior is
  15155.                 undefined.
  15156.  
  15157.  Each conversion character shall result in fetching zero or more
  15158.  arguments.  The results are undefined if there are insufficient arguments
  15159.  for the format.  If the format is exhausted while arguments remain, the
  15160.  excess arguments shall be ignored.
  15161.  
  15162.  The _c_o_n_v_e_r_s_i_o_n _c_h_a_r_a_c_t_e_r_s and their meanings are:
  15163.  
  15164.     d,i,o,u,x,X The integer argument shall be written as signed decimal (d
  15165.                 or i), unsigned octal (o), unsigned decimal (u), or
  15166.                 unsigned hexadecimal notation (x and X).  The d and i
  15167.                 specifiers shall convert to signed decimal in the style
  15168.                 [-]_d_d_d_d.  The x conversion shall use the numbers and
  15169.  
  15170.  
  15171.                Copyright c 1991 IEEE.  All rights reserved.
  15172.       This is an unapproved IEEE Standards Draft, subject to change.
  15173.  
  15174.  
  15175.  
  15176.  
  15177.  
  15178.  200                                2 Terminology and General Requirements
  15179.  
  15180.  
  15181.  
  15182.  
  15183.  
  15184.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15185.  
  15186.                 letters 0123456789abcdef and the X conversion shall use
  15187.                 the numbers and letters 0123456789ABCDEF.  The _p_r_e_c_i_s_i_o_n
  15188.                 component of the argument shall specify the minimum number
  15189.                 of digits to appear.  If the value being converted can be
  15190.                 represented in fewer digits than the specified minimum, it
  15191.                 shall be expanded with leading zeroes.  The default
  15192.                 precision shall be 1.  The result of converting a zero
  15193.                 value with a precision of 0 shall be no characters.  If
  15194.                 both the field width and precision are omitted, the
  15195.                 implementation may precede and/or follow numeric arguments
  15196.                 of types d, i, and u with <blank>s; arguments of type o
  15197.                 (octal) may be preceded with leading zeroes.
  15198.  
  15199.     f           The floating point number argument shall be written in
  15200.                 decimal notation in the style "[-]_d_d_d._d_d_d", where the
  15201.                 number of digits after the radix character (shown here as
  15202.                 a decimal point) shall be equal to the _p_r_e_c_i_s_i_o_n
  15203.                 specification.  The LC_NUMERIC locale category shall
  15204.                 determine the radix character to use in this format.  If
  15205.                 the _p_r_e_c_i_s_i_o_n is omitted from the argument, six digits
  15206.                 shall be written after the radix character; if the
  15207.                 _p_r_e_c_i_s_i_o_n is explicitly 0, no radix character shall
  15208.                 appear.
  15209.  
  15210.     e,E         The floating point number argument shall be written in the
  15211.                 style "[-]_d._d_d_d_e+__d_d" (the symbol +_ indicates either a plus
  15212.                 or minus sign), where there is one digit before the radix
  15213.                 character (shown here as a decimal point) and the number
  15214.                 of digits after it is equal to the precision.  The
  15215.                 LC_NUMERIC locale category shall determine the radix
  15216.                 character to use in this format.  When the precision is
  15217.                 missing, six digits shall be written after the radix
  15218.                 character; if the precision is 0, no radix character shall
  15219.                 appear.  The E conversion character shall produce a number
  15220.                 with E instead of e introducing the exponent.  The
  15221.                 exponent always shall contain at least two digits.
  15222.                 However, if the value to be written requires an exponent
  15223.                 greater than two digits, additional exponent digits shall
  15224.                 be written as necessary.
  15225.  
  15226.     g,G         The floating point number argument shall be written in
  15227.                 style f or e (or in style E in the case of a G conversion
  15228.                 character), with the precision specifying the number of
  15229.                 significant digits.  The style used depends on the value
  15230.                 converted:  style e shall be used only if the exponent
  15231.                 resulting from the conversion is less than -4 or greater
  15232.                 than or equal to the precision.  Trailing zeroes shall be
  15233.                 removed from the result.  A radix character shall appear
  15234.                 only if it is followed by a digit.
  15235.  
  15236.  
  15237.                Copyright c 1991 IEEE.  All rights reserved.
  15238.       This is an unapproved IEEE Standards Draft, subject to change.
  15239.  
  15240.  
  15241.  
  15242.  
  15243.  
  15244.  2.12 File Format Notation                                             201
  15245.  
  15246.  
  15247.  
  15248.  
  15249.  
  15250.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15251.  
  15252.     c           The integer argument shall be converted to an _u_n_s_i_g_n_e_d
  15253.                 _c_h_a_r and the resulting byte shall be written.
  15254.  
  15255.     s           The argument shall be taken to be a string and bytes from
  15256.                 the string shall be written until the end of the string or
  15257.                 the number of bytes indicated by the _p_r_e_c_i_s_i_o_n
  15258.                 specification of the argument is reached.  If the
  15259.                 precision is omitted from the argument, it shall be taken
  15260.                 to be infinite, so all bytes up to the end of the string
  15261.                 shall be written.
  15262.  
  15263.     %           Write a % character; no argument shall be converted.
  15264.  
  15265.  In no case does a nonexistent or insufficient _f_i_e_l_d _w_i_d_t_h cause
  15266.  truncation of a field; if the result of a conversion is wider than the
  15267.  field width, the field shall be simply expanded to contain the conversion
  15268.  result.
  15269.  
  15270.  BEGIN_RATIONALE
  15271.  
  15272.  
  15273.  2.12.1  File Format Notation Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  15274.          _P_1_0_0_3._2)
  15275.  
  15276.  This clause was originally derived from the description of _p_r_i_n_t_f() in
  15277.  the _S_V_I_D, but it has been updated following the publication of the
  15278.  C Standard {7}.  It is not identical to the C Standard's {7} _p_r_i_n_t_f(), as
  15279.  it deals with integers as being essentially one type, disregarding
  15280.  possible internal differences between _i_n_t, _s_h_o_r_t, and _l_o_n_g.  It has also
  15281.  had some of the internal C language dependencies removed (such as the
  15282.  requirement for null-terminated strings).
  15283.  
  15284.  This standard provides a rigorous description of the format of utility
  15285.  input and output files.  It is the intention of this standard that these
  15286.  descriptions be adequate sources of information so that portable
  15287.  applications can use other utilities such as lex or awk to reliably parse
  15288.  the output of these utilities as their input in, say a pipeline.
  15289.  
  15290.  The notation for spaces allows some flexibility for application output.
  15291.  Note that an empty character position in _f_o_r_m_a_t represents one or more
  15292.  <blank> characters on the output (not _w_h_i_t_e _s_p_a_c_e, which can include
  15293.  <newline>s).  Therefore, another utility that reads that output as its
  15294.  input must be prepared to parse the data using _s_c_a_n_f(), awk, etc.  The W
  15295.  character is used when exactly one <space> is output.
  15296.  
  15297.  The treatment of integers and spaces is different from the real _p_r_i_n_t_f(),
  15298.  in that they can be surrounded with <blank>_s.  This was done so that,
  15299.  given a format such as:
  15300.  
  15301.  
  15302.  
  15303.                Copyright c 1991 IEEE.  All rights reserved.
  15304.       This is an unapproved IEEE Standards Draft, subject to change.
  15305.  
  15306.  
  15307.  
  15308.  
  15309.  
  15310.  202                                2 Terminology and General Requirements
  15311.  
  15312.  
  15313.  
  15314.  
  15315.  
  15316.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15317.  
  15318.        "%d\n", <_f_o_o>
  15319.  
  15320.  the implementation could use a real _p_r_i_n_t_f() such as
  15321.  
  15322.        printf("%6d\n", foo);
  15323.  
  15324.  and still conform.  It would have been possible for the standard to use
  15325.  "%6d\n", but it would have been difficult to pick a number that would
  15326.  have pleased everyone.  This notation is thus somewhat like _s_c_a_n_f() in
  15327.  addition to _p_r_i_n_t_f().
  15328.  
  15329.  The _p_r_i_n_t_f() function was chosen as a model as most of the working group
  15330.  was familiar with it and it was thought that many of the readers would be
  15331.  as well.
  15332.  
  15333.  One difference from the C function _p_r_i_n_t_f() is that the l and h
  15334.  conversion characters are not used.  As expressed by this standard, there
  15335.  is no differentiation between decimal values for _i_n_ts versus _l_o_n_gs versus
  15336.  _s_h_o_r_ts.  The specifications %d or %i should be interpreted as an
  15337.  arbitrary length sequence of digits.  Also, no distinction is made
  15338.  between single precision and double precision numbers (_f_l_o_a_t/_d_o_u_b_l_e in
  15339.  C).  These are simply referred to as floating point numbers.
  15340.  
  15341.  Many of the output descriptions in this standard use the term _l_i_n_e, such
  15342.  as:
  15343.  
  15344.        "%s", <_i_n_p_u_t _l_i_n_e>
  15345.  
  15346.  Since the definition of _l_i_n_e includes the trailing <newline> character
  15347.  already, there is no need to include a "\n" in the format; a double
  15348.  <newline> would otherwise result.
  15349.  
  15350.  In the language at the end of the clause:
  15351.  
  15352.        ``In no case does a nonexistent or insufficient _f_i_e_l_d _w_i_d_t_h
  15353.        cause truncation of a field; ...''
  15354.  
  15355.  the term ``field width'' should not be confused with the term
  15356.  ``precision'' used in the description of %s.
  15357.  
  15358.  Examples:
  15359.  
  15360.  To represent the output of a program that prints a date and time in the
  15361.  form Sunday, July 3, 10:02, where <_w_e_e_k_d_a_y> and <_m_o_n_t_h> are strings:
  15362.  
  15363.        "%s,W%sW%d,W%d:%.2d\n", <_w_e_e_k_d_a_y>, <_m_o_n_t_h>, <_d_a_y>, <_h_o_u_r>,
  15364.        <_m_i_n>
  15365.  
  15366.  
  15367.  
  15368.  
  15369.                Copyright c 1991 IEEE.  All rights reserved.
  15370.       This is an unapproved IEEE Standards Draft, subject to change.
  15371.  
  15372.  
  15373.  
  15374.  
  15375.  
  15376.  2.12 File Format Notation                                             203
  15377.  
  15378.  
  15379.  
  15380.  
  15381.  
  15382.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15383.  
  15384.  To show J written to 5 decimal places:
  15385.  
  15386.        "piW=W%.5f\n", <_v_a_l_u_e _o_f J>
  15387.  
  15388.  To show an input file format consisting of five colon-separated fields:
  15389.  
  15390.        "%s:%s:%s:%s:%s\n", <_a_r_g_1>, <_a_r_g_2>, <_a_r_g_3>, <_a_r_g_4>, <_a_r_g_5>
  15391.  
  15392.  END_RATIONALE
  15393.  
  15394.  
  15395.  
  15396.  2.13  Configuration Values
  15397.  
  15398.  
  15399.  2.13.1  Symbolic Limits
  15400.  
  15401.  This clause lists magnitude limitations imposed by a specific
  15402.  implementation.  The braces notation, {LIMIT}, is used in this standard
  15403.  to indicate these values, but the braces are not part of the name.  The
  15404.  values specified in Table 2-16 represent the lowest values conforming
  15405.  implementations shall provide; and consequently, the largest values on
  15406.  which an application can rely without further enquiries, as described
  15407.  below.  These values shall be accessible to applications via the getconf
  15408.  utility (see 4.26) and through the interfaces described in 7.8.2, [such
  15409.  as _s_y_s_c_o_n_f() in the C binding].  The literal names shown in the table
  15410.  apply only to the getconf utility; the high-level-language binding shall
  15411.  describe the exact form of each name to be used by the interfaces in that
  15412.  binding.
  15413.  
  15414.  Implementations may provide more liberal, or less restrictive, values
  15415.  than shown in Table 2-16.  These possibly more liberal values are
  15416.  accessible using the symbols in Table 2-17.
  15417.  
  15418.  The functions in 7.8.2 [such as _s_y_s_c_o_n_f() in the C binding] or the
  15419.  getconf utility shall return the value of each symbol on each specific
  15420.  implementation.  The value so retrieved shall be the largest, or most
  15421.  liberal, value that shall be available throughout the session lifetime,
  15422.  as determined at session creation.  The literal names shown in the table
  15423.  apply only to the getconf utility; the high-level-language binding shall
  15424.  describe the exact form of each name to be used by the interfaces in that
  15425.  binding.
  15426.  
  15427.  All numerical limits defined by POSIX.1 {8}, such as {PATH_MAX}, also
  15428.  apply to this standard.  (See POSIX.1 {8} 2.8.)  All the utilities
  15429.  defined by this standard are implicitly limited by these values, unless
  15430.  otherwise noted in the utility descriptions.
  15431.  
  15432.  
  15433.  
  15434.  
  15435.                Copyright c 1991 IEEE.  All rights reserved.
  15436.       This is an unapproved IEEE Standards Draft, subject to change.
  15437.  
  15438.  
  15439.  
  15440.  
  15441.  
  15442.  204                                2 Terminology and General Requirements
  15443.  
  15444.  
  15445.  
  15446.  
  15447.  
  15448.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15449.  
  15450.  
  15451.                 Table 2-16  -  Utility Limit Minimum Values
  15452.  __________________________________________________________________________________________________________________________________________________
  15453.              Name                       Description              Value
  15454.    ____________________________________________________________________
  15455.  
  15456.    {POSIX2_BC_BASE_MAX}        The maximum _o_b_a_s_e value            99
  15457.                                allowed by the bc utility.
  15458.    {POSIX2_BC_DIM_MAX}         The maximum number of elements   2048
  15459.                                permitted in an array by the
  15460.                                bc utility.
  15461.    {POSIX2_BC_SCALE_MAX}       The maximum _s_c_a_l_e value            99
  15462.                                allowed by the bc utility.
  15463.    {POSIX2_BC_STRING_MAX}      The maximum length of a string   1000
  15464.                                constant accepted by the bc
  15465.                                utility.
  15466.    {POSIX2_COLL_WEIGHTS_MAX}   The maximum number of weights       2
  15467.                                that can be assigned to an
  15468.                                entry of the LC_COLLATE order
  15469.                                keyword in the locale
  15470.                                definition file; see
  15471.                                2.5.2.2.3.
  15472.    {POSIX2_EXPR_NEST_MAX}      The maximum number of              32
  15473.                                expressions that can be nested
  15474.                                within parentheses by the expr
  15475.                                utility.
  15476.    {POSIX2_LINE_MAX}           Unless otherwise noted, the      2048
  15477.                                maximum length, in bytes, of a
  15478.                                utility's input line (either
  15479.                                standard input or another
  15480.                                file), when the utility is
  15481.                                described as processing text
  15482.                                files.  The length includes
  15483.                                room for the trailing
  15484.                                <newline>.
  15485.    {POSIX2_RE_DUP_MAX}         The maximum number of repeated    255
  15486.                                occurrences of a regular
  15487.                                expression permitted when
  15488.                                using the interval notation
  15489.                                \{_m,_n\}; see 2.8.3.3.
  15490.    {POSIX2_VERSION}            This value indicates the          199???     11
  15491.                                version of the utilities in                  1
  15492.                                this standard that are                       1
  15493.                                provided by the                              1
  15494.                                implementation.  It will                     1
  15495.                                change with each published                   1
  15496.                                version of this standard.                    1
  15497.  __________________________________________________________________________________________________________________________________________________
  15498.  
  15499.  
  15500.  
  15501.                Copyright c 1991 IEEE.  All rights reserved.
  15502.       This is an unapproved IEEE Standards Draft, subject to change.
  15503.  
  15504.  
  15505.  
  15506.  
  15507.  
  15508.  2.13 Configuration Values                                             205
  15509.  
  15510.  
  15511.  
  15512.  
  15513.  
  15514.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15515.  
  15516.  
  15517.                   Table 2-17  -  Symbolic Utility Limits
  15518.  __________________________________________________________________________________________________________________________________________________
  15519.                                                        Minimum
  15520.           Name              Description                 Value
  15521.    ____________________________________________________________________
  15522.  
  15523.    {BC_BASE_MAX}      The maximum _o_b_a_s_e value {POSIX2_BC_BASE_MAX}
  15524.                       allowed by the bc
  15525.                       utility.
  15526.    {BC_DIM_MAX}       The maximum number of   {POSIX2_BC_DIM_MAX}
  15527.                       elements permitted in
  15528.                       an array by the bc
  15529.                       utility.
  15530.    {BC_SCALE_MAX}     The maximum _s_c_a_l_e value {POSIX2_BC_SCALE_MAX}
  15531.                       allowed by the bc
  15532.                       utility.
  15533.    {BC_STRING_MAX}    The maximum length of a {POSIX2_BC_STRING_MAX}
  15534.                       string constant
  15535.                       accepted by the bc
  15536.                       utility.
  15537.    {COLL_WEIGHTS_MAX} The maximum number of   {POSIX2_COLL_WEIGHTS_MAX}
  15538.                       weights that can be
  15539.                       assigned to an entry of
  15540.                       the LC_COLLATE order
  15541.                       keyword in the locale
  15542.                       definition file; see
  15543.                       2.5.2.2.3.
  15544.    {EXPR_NEST_MAX}    The maximum number of   {POSIX2_EXPR_NEST_MAX}
  15545.                       expressions that can be
  15546.                       nested within
  15547.                       parentheses by the expr
  15548.                       utility.
  15549.    {LINE_MAX}         Unless otherwise noted, {POSIX2_LINE_MAX}
  15550.                       the maximum length, in
  15551.                       bytes, of a utility's
  15552.                       input line (either
  15553.                       standard input or
  15554.                       another file), when the
  15555.                       utility is described as
  15556.                       processing text files.
  15557.                       The length includes
  15558.                       room for the trailing
  15559.                       <newline>.
  15560.                       The maximum number of
  15561.                       repeated occurrences of
  15562.                       a regular expression
  15563.                       permitted when using
  15564.                       the interval notation
  15565.                       \{_m,_n\}; see 2.8.3.3.
  15566.  
  15567.                Copyright c 1991 IEEE.  All rights reserved.
  15568.       This is an unapproved IEEE Standards Draft, subject to change.
  15569.  
  15570.  
  15571.  
  15572.  
  15573.  
  15574.  206                                2 Terminology and General Requirements
  15575.  
  15576.  
  15577.  
  15578.  
  15579.  
  15580.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15581.  
  15582.    {RE_DUP_MAX}                               {POSIX2_RE_DUP_MAX}
  15583.  
  15584.  
  15585.  
  15586.  
  15587.  
  15588.  __________________________________________________________________________________________________________________________________________________
  15589.  
  15590.  
  15591.  It is not guaranteed that the application can in fact push a value to the
  15592.  implementation's specified limit in any given case, or at all, as a lack
  15593.  of virtual memory or other resources may prevent this.  The limit value
  15594.  indicates only that the implementation does not specifically impose any
  15595.  arbitrary, more restrictive limit.
  15596.  
  15597.  BEGIN_RATIONALE
  15598.  
  15599.  
  15600.  2.13.1.1  Symbolic Limits Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  15601.            _P_1_0_0_3._2)
  15602.  
  15603.  This clause grew out of an idea that originated in POSIX.1 {8}, in the
  15604.  form of _s_y_s_c_o_n_f() and _p_a_t_h_c_o_n_f().  (In fact, the same person wrote the
  15605.  original text for both standards.)  The idea is that a Strictly
  15606.  Conforming POSIX.2 Application can be written to use the most restrictive
  15607.  values that a minimal system can provide, but it shouldn't have to.  The
  15608.  values shown in Table 2-17 represent compromises so that some vendors can
  15609.  use historically-limited versions of UNIX system utilities.  They are the
  15610.  highest values that Strictly Conforming POSIX.2 Applications or
  15611.  Conforming POSIX.2 Applications can assume, given no other information.
  15612.  
  15613.  However, by using getconf or _s_y_s_c_o_n_f(), the elegant application can
  15614.  tailor itself to the more liberal values on some of the specific
  15615.  instances of specific implementations.
  15616.  
  15617.  There is no explicitly-stated requirement that an implementation provide
  15618.  finite limits for any of these numeric values; the implementation is free
  15619.  to provide essentially unbounded capabilities (where it makes sense),
  15620.  stopping only at reasonable points such as {ULONG_MAX} (from the
  15621.  C Standard {7} via POSIX.1 {8}).  Therefore, applications desiring to
  15622.  tailor themselves to the values on a particular implementation need to be
  15623.  ready for possibly huge values; it may not be a good idea to blindly
  15624.  allocate a buffer for an input line based on the value of {LINE_MAX}, for
  15625.  instance.  However, unlike POSIX.1 {8}, there is no set of limits in this
  15626.  standard that return a special indication meaning ``unbounded.''  The
  15627.  implementation should always return an actual number, even if the number
  15628.  is very large.
  15629.  
  15630.  
  15631.  
  15632.  
  15633.                Copyright c 1991 IEEE.  All rights reserved.
  15634.       This is an unapproved IEEE Standards Draft, subject to change.
  15635.  
  15636.  
  15637.  
  15638.  
  15639.  
  15640.  2.13 Configuration Values                                             207
  15641.  
  15642.  
  15643.  
  15644.  
  15645.  
  15646.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15647.  
  15648.  The statement
  15649.  
  15650.        ``It is not guaranteed that the application ...
  15651.  
  15652.  is an indication that many of these limits are designed to ensure that
  15653.  implementors design their utilities without arbitrary constraints related
  15654.  to unimaginative programming.  There are certainly conditions under which
  15655.  combinations of options can cause failures that would not render an
  15656.  implementation nonconforming.  For example, {EXPR_NEST_MAX} and {ARG_MAX}
  15657.  could collide when expressions are large; combinations of {BC_SCALE_MAX}
  15658.  and {BC_DIM_MAX} could exceed virtual memory.
  15659.  
  15660.  In POSIX.2, the notion of a limit being guaranteed for the process
  15661.  lifetime, as it is in POSIX.1 {8}, is not as useful to a shell script.
  15662.  The getconf utility is probably a process itself, so the guarantee would
  15663.  be valueless.  Therefore, POSIX.2 requires the guarantee to be for the
  15664.  session lifetime.  This will mean that many vendors will either return
  15665.  very conservative values or possibly implement getconf as a built-in.
  15666.  
  15667.  It may seem confusing to have limits that apply only to a single utility
  15668.  grouped into one global clause.  However, the alternative, which would be
  15669.  to disperse them out into their utility description clauses, would cause
  15670.  great difficulty when _s_y_s_c_o_n_f() and getconf were described.  Therefore,
  15671.  the working group chose the global approach.
  15672.  
  15673.  Each language binding could provide symbol names that are slightly
  15674.  different than are shown here.  For example, the C binding prefixes the
  15675.  symbols with a leading underscore.
  15676.  
  15677.  The following comments describe selection criteria for the symbols and
  15678.  their values.
  15679.  
  15680.     {ARG_MAX}
  15681.           This is defined by POSIX.1 {8}.  Unfortunately, it is very
  15682.           difficult for a portable application to deal with this value, as
  15683.           it does not know how much of its argument space is being
  15684.           consumed by the user's environment variables.
  15685.  
  15686.     {BC_BASE_MAX}
  15687.     {BC_DIM_MAX}
  15688.     {BC_SCALE_MAX}
  15689.           These were originally one value, {BC_SCALE_MAX}, but it was
  15690.           unreasonable to link all three concepts into one limit.
  15691.  
  15692.     {CHILD_MAX}
  15693.           This is defined by POSIX.1 {8}.
  15694.  
  15695.     {CUT_FIELD_MAX}
  15696.           This value was removed from an earlier draft.  It represented
  15697.  
  15698.  
  15699.                Copyright c 1991 IEEE.  All rights reserved.
  15700.       This is an unapproved IEEE Standards Draft, subject to change.
  15701.  
  15702.  
  15703.  
  15704.  
  15705.  
  15706.  208                                2 Terminology and General Requirements
  15707.  
  15708.  
  15709.  
  15710.  
  15711.  
  15712.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15713.  
  15714.           the maximum length of the _l_i_s_t argument to the cut -c or -f
  15715.           options.  Since the length is now unspecified, the utility
  15716.           should have to deal with arbitrarily long lists, as long as
  15717.           {ARG_MAX} is not exceeded.
  15718.  
  15719.     {CUT_LINE_MAX}
  15720.           This value was removed from an earlier draft.  Historical cuts
  15721.           have had input line limits of 1024; this removal therefore
  15722.           mandates that a conforming cut shall process files with lines of  1
  15723.           unlimited length.                                                 1
  15724.  
  15725.     {DEPTH_MAX}
  15726.           This directory-traversing depth limit (which at one time applied
  15727.           to rm and find) was removed from an earlier draft for two major
  15728.           reasons:
  15729.  
  15730.            (1)  It could be a security problem if utilities searching for
  15731.                 files could not descend below a published depth; this
  15732.                 would be a semi-reliable means of hiding files from the
  15733.                 administrator.
  15734.  
  15735.            (2)  There is no reason a reasonable implementation should have
  15736.                 to limit itself in this way.
  15737.  
  15738.     {ED_FILE_MAX}
  15739.           This value was removed from an earlier draft.  Historical eds
  15740.           have had very small file limits; since {ED_FILE_MAX} is no
  15741.           longer specified, implementations have to document the limits as
  15742.           described in 2.11.  It is recommended that implementations set
  15743.           much more reasonable file size limits as they modify ed to deal
  15744.           with other features required by POSIX.2.
  15745.  
  15746.     {ED_LINE_MAX}
  15747.           This value was removed from an earlier draft.  Historical eds
  15748.           have had small input line limits; this removal therefore
  15749.           mandates that a conforming ed shall process files with lines of
  15750.           length {LINE_MAX}.
  15751.  
  15752.     {COLL_WEIGHTS_MAX}
  15753.           The weights assigned to order can be considered as ``passes''
  15754.           through the collation algorithm.
  15755.  
  15756.     {EXPR_NEST_MAX}
  15757.           The value for expression nesting was borrowed from the
  15758.           C Standard {7}.
  15759.  
  15760.     {FIND_DEPTH_MAX}
  15761.           This was removed from an earlier draft in favor of a common
  15762.  
  15763.  
  15764.  
  15765.                Copyright c 1991 IEEE.  All rights reserved.
  15766.       This is an unapproved IEEE Standards Draft, subject to change.
  15767.  
  15768.  
  15769.  
  15770.  
  15771.  
  15772.  2.13 Configuration Values                                             209
  15773.  
  15774.  
  15775.  
  15776.  
  15777.  
  15778.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15779.  
  15780.           value, {DEPTH_MAX}.
  15781.  
  15782.     {FIND_FILESYS_MAX}
  15783.           This was removed from an earlier draft.  It indicated the limit
  15784.           of the number of file systems that find could traverse in its
  15785.           search.  It was dropped because this standard does not really
  15786.           acknowledge the historical nature of separate file systems.
  15787.  
  15788.     {FIND_NEWER_MAX}
  15789.           This value, which allowed find to limit the number of -newer
  15790.           operands it processed, was deleted from an earlier draft.  It
  15791.           was felt to be a vestige of a particular implementation with an
  15792.           incorrect programming algorithm that should not limit
  15793.           applications.
  15794.  
  15795.     {JOIN_LINE_MAX}
  15796.           This value was removed from an earlier draft.  Historical joins
  15797.           have had input line limits of 1024; this removal therefore
  15798.           mandates that a conforming join shall process files with lines
  15799.           of length {LINE_MAX}.
  15800.  
  15801.     {LINE_MAX}
  15802.           This is a global limit that affects all utilities, unless
  15803.           otherwise noted.  The {MAX_CANON} value from POSIX.1 {8} may
  15804.           further limit input lines from terminals.  The {LINE_MAX} value
  15805.           was the subject of much debate and is a compromise between those
  15806.           who wished unlimited lines and those who understood that many
  15807.           historical utilities were written with fixed buffers.
  15808.           Frequently, utility writers selected the UNIX system constant
  15809.           BUFSIZ to allocate these buffers; therefore, some utilities were
  15810.           limited to 512 bytes for I/O lines, while others achieved 4096
  15811.           or greater.
  15812.  
  15813.           It should be noted that {LINE_MAX} applies only to input line
  15814.           length; there is no requirement in the standard that limits the
  15815.           length of output lines.  Utilities such as awk, sed, and paste
  15816.           could theoretically construct lines longer than any of the input
  15817.           lines they received, depending on the options used or the
  15818.           instructions from the application.  They are not required to
  15819.           truncate their output to {LINE_MAX}.  It is the responsibility
  15820.           of the application to deal with this.  If the output of one of
  15821.           those utilities is to be piped into another of the standard
  15822.           utilities, line lengths restrictions will have to be considered;
  15823.           the fold utility, among others, could be used to ensure that
  15824.           only reasonable line lengths reach utilities or applications.
  15825.  
  15826.     {LINK_MAX}
  15827.           This is defined by POSIX.1 {8}.
  15828.  
  15829.  
  15830.  
  15831.                Copyright c 1991 IEEE.  All rights reserved.
  15832.       This is an unapproved IEEE Standards Draft, subject to change.
  15833.  
  15834.  
  15835.  
  15836.  
  15837.  
  15838.  210                                2 Terminology and General Requirements
  15839.  
  15840.  
  15841.  
  15842.  
  15843.  
  15844.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15845.  
  15846.     {LP_LINE_MAX}
  15847.           This value was removed from an earlier draft.  Since so little
  15848.           is being required for the details of the lp utility, it made
  15849.           little sense to specify how long its output lines are.  Thus,
  15850.           implementations of lp will be expected to deal with lines up to
  15851.           {LINE_MAX}, but whether those lines print sensibly on every
  15852.           device is unspecified.
  15853.  
  15854.     {MAX_CANON}
  15855.           This is defined by POSIX.1 {8}.
  15856.  
  15857.     {MAX_INPUT}
  15858.           This is defined by POSIX.1 {8}.
  15859.  
  15860.     {NAME_MAX}
  15861.           This is defined by POSIX.1 {8}.
  15862.  
  15863.     {NGROUPS_MAX}
  15864.           This is defined by POSIX.1 {8}.
  15865.  
  15866.     {OPEN_MAX}
  15867.           This is defined by POSIX.1 {8}.
  15868.  
  15869.     {PATH_MAX}
  15870.           This is defined by POSIX.1 {8}.
  15871.  
  15872.     {PIPE_BUF}
  15873.           This is defined by POSIX.1 {8}.
  15874.  
  15875.     {RM_DEPTH_MAX}
  15876.           This was removed from an earlier draft in favor of a common
  15877.           value, {DEPTH_MAX}.
  15878.  
  15879.     {RE_DUP_MAX}
  15880.           The value selected is consistent with historical practice.
  15881.  
  15882.     {SED_PATTERN_MAX}
  15883.           This symbolic value, the size of the sed pattern space, was
  15884.           replaced by a specific value in the sed description.  It is
  15885.           unlikely that any real application would ever need to access
  15886.           this value symbolically.
  15887.  
  15888.     {SORT_LINE_MAX}
  15889.           This was removed from an earlier draft.  Now that cut and fold
  15890.           can handle unlimited-length input lines, a special long input
  15891.           line limit for sort is not needed.
  15892.  
  15893.  There are different limits associated with command lines and input to
  15894.  utilities, depending on the method of invocation.  In the case of a C
  15895.  
  15896.  
  15897.                Copyright c 1991 IEEE.  All rights reserved.
  15898.       This is an unapproved IEEE Standards Draft, subject to change.
  15899.  
  15900.  
  15901.  
  15902.  
  15903.  
  15904.  2.13 Configuration Values                                             211
  15905.  
  15906.  
  15907.  
  15908.  
  15909.  
  15910.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  15911.  
  15912.  program _e_x_e_c-ing a utility, {ARG_MAX} is the underlying limit.  In the
  15913.  case of the shell reading a script and _e_x_e_c-ing a utility, {LINE_MAX}
  15914.  limits the length of lines the shell is required to process and {ARG_MAX}
  15915.  will still be a limit.  If a user is entering a command on a terminal to
  15916.  the shell, requesting that it invoke the utility, {MAX_INPUT} may
  15917.  restrict the length of the line that can be given to the shell to a value
  15918.  below {LINE_MAX}.
  15919.  
  15920.  END_RATIONALE
  15921.  
  15922.  
  15923.  2.13.2  Symbolic Constants for Portability Specifications
  15924.  
  15925.  
  15926.            Table 2-18  -  Optional Facility Configuration Values
  15927.  __________________________________________________________________________________________________________________________________________________
  15928.         Name                                   Description
  15929.  _________________________________________________________________________
  15930.  
  15931.  {POSIX2_C_BIND}                The C language development facilities in
  15932.                                 Annex A support the C Language Bindings
  15933.                                 Option (see Annex B).
  15934.  {POSIX2_C_DEV}                 The system supports the C Language
  15935.                                 Development Utilities Option (see
  15936.                                 Annex A).
  15937.  {POSIX2_FORT_DEV}              The system supports the FORTRAN
  15938.                                 Development Utilities Option (see
  15939.                                 Annex C).
  15940.  {POSIX2_FORT_RUN}              The system supports the FORTRAN Runtime
  15941.                                 Utilities Option (see Annex C).
  15942.  {POSIX2_LOCALEDEF}             The system supports the creation of
  15943.                                 locales as described in 4.35.
  15944.  {POSIX2_SW_DEV}                The system supports the Software
  15945.                                 Development Utilities Option (see Section
  15946.                                 6).
  15947.  __________________________________________________________________________________________________________________________________________________
  15948.  
  15949.  
  15950.  Table 2-18 lists symbols that can be used by the application to determine
  15951.  which optional facilities are present on the implementation.  The
  15952.  functions defined in 7.8.2 [such as _s_y_s_c_o_n_f()] or the getconf utility can
  15953.  be used to retrieve the value of each symbol on each specific
  15954.  implementation.  The literal names shown in the table apply only to the
  15955.  getconf utility; the high-level-language binding shall describe the exact
  15956.  form of each name to be used by the interfaces in that binding.
  15957.  
  15958.  Each of these symbols shall be considered valid names by the
  15959.  implementation.  Each shall be defined on the system with a value of 1 if
  15960.  the corresponding option is supported; otherwise, the symbol shall be
  15961.  undefined.
  15962.  
  15963.                Copyright c 1991 IEEE.  All rights reserved.
  15964.       This is an unapproved IEEE Standards Draft, subject to change.
  15965.  
  15966.  
  15967.  
  15968.  
  15969.  
  15970.  212                                2 Terminology and General Requirements
  15971.  
  15972.  
  15973.  
  15974.  
  15975.  
  15976.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  15977.  
  15978.  BEGIN_RATIONALE
  15979.  
  15980.  
  15981.  2.13.2.1  Symbolic Constants for Portability Specifications Rationale.
  15982.            (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  15983.  
  15984.  When an option is supported, getconf returns a value of 1.  For example,
  15985.  when C development is supported:
  15986.  
  15987.        if [ "$(getconf POSIX2_C_DEV)" -eq 1 ]; then
  15988.                echo C supported
  15989.        fi
  15990.  
  15991.  The _s_y_s_c_o_n_f() function in the C binding would return 1.
  15992.  
  15993.  The following comments describe selection criteria for the symbols and
  15994.  their values.
  15995.  
  15996.     {POSIX2_C_BIND}
  15997.     {POSIX2_C_DEV}
  15998.     {POSIX2_FORT_DEV}
  15999.     {POSIX2_SW_DEV}
  16000.           These were renamed from _POSIX_* in Draft 9 after it was pointed
  16001.           out that each of the POSIX standards should keep generally in
  16002.           its own namespace.
  16003.  
  16004.           It is possible for some (usually privileged) operations to
  16005.           remove utilities that support these options, or otherwise render
  16006.           these options unsupported.  The header files, the _s_y_s_c_o_n_f()
  16007.           function, or the getconf utility will not necessarily detect
  16008.           such actions, in which case they should not be considered as
  16009.           rendering the implementation nonconforming.  A test suite should
  16010.           not attempt tests like:
  16011.  
  16012.                 rm /usr/bin/c89
  16013.                 getconf POSIX2_C_DEV
  16014.  
  16015.     {_POSIX_LOCALEDEF}
  16016.           This symbol was introduced to allow implementations to restrict
  16017.           supported locales to only those supplied by the implementation.
  16018.  
  16019.  END_RATIONALE
  16020.  
  16021.  
  16022.  
  16023.  
  16024.  
  16025.  
  16026.  
  16027.  
  16028.  
  16029.                Copyright c 1991 IEEE.  All rights reserved.
  16030.       This is an unapproved IEEE Standards Draft, subject to change.
  16031.  
  16032.  
  16033.  
  16034.  
  16035.  
  16036.  2.13 Configuration Values                                             213
  16037.  
  16038.  
  16039.  
  16040.  
  16041.  
  16042.  
  16043.  
  16044.  
  16045.  
  16046.  
  16047.  
  16048.  
  16049.  
  16050.  
  16051.  
  16052.  
  16053.  
  16054.  
  16055.  
  16056.  
  16057.  
  16058.  
  16059.  
  16060.  
  16061.  
  16062.  
  16063.  
  16064.  
  16065.  
  16066.  
  16067.  
  16068.  
  16069.  
  16070.  
  16071.  
  16072.  
  16073.  
  16074.  
  16075.  
  16076.  
  16077.  
  16078.  
  16079.  
  16080.  
  16081.  
  16082.  
  16083.  
  16084.  
  16085.  
  16086.  
  16087.  
  16088.  
  16089.  
  16090.  
  16091.  
  16092.  
  16093.  
  16094.  
  16095.  
  16096.  
  16097.  
  16098.  
  16099.  
  16100.  
  16101.  
  16102.  
  16103.  
  16104.  
  16105.  
  16106.  
  16107.  
  16108.                                                              P1003.2/D11.2
  16109.  
  16110.  
  16111.  
  16112.  
  16113.  
  16114.  
  16115.  
  16116.  
  16117.                      Section 3: Shell Command Language
  16118.  
  16119.  
  16120.  
  16121.  The shell is a command language interpreter.  This section describes the
  16122.  syntax of that command language as it is used by the sh utility and the
  16123.  functions in 7.1 [such as _s_y_s_t_e_m() and _p_o_p_e_n() in the C binding].
  16124.  
  16125.  The shell operates according to the following general overview of
  16126.  operations.  The specific details are included in the cited clauses and
  16127.  subclauses of this section.  The shell:
  16128.  
  16129.      (1)  Reads its input from a file (see sh in 4.56), from the -c
  16130.           option, or from one of the functions in 7.1.  If the first line
  16131.           of a file of shell commands starts with the characters #!, the
  16132.           results are unspecified.
  16133.  
  16134.      (2)  Breaks the input into tokens:  words and operators.  (See 3.3.)
  16135.  
  16136.      (3)  Parses the input into simple (3.9.1) and compound (3.9.4)
  16137.           commands.
  16138.  
  16139.      (4)  Performs various expansions (separately) on different parts of
  16140.           each command, resulting in a list of pathnames and fields to be
  16141.           treated as a command and arguments (3.6).
  16142.  
  16143.      (5)  Performs redirection (3.7) and removes redirection operators and
  16144.           their operands from the parameter list.
  16145.  
  16146.      (6)  Executes a function (3.9.5), built-in (3.14), executable file,
  16147.           or script, giving the name of the command (or, in the case of a   1
  16148.           function within a script, the name of the script) as the          1
  16149.           ``zero'th'' argument and the remaining words and fields as
  16150.           parameters (3.9.1.1).
  16151.  
  16152.      (7)  Optionally waits for the command to complete and collects the
  16153.           exit status (3.8.2).
  16154.  
  16155.  BEGIN_RATIONALE
  16156.  
  16157.  
  16158.  
  16159.  
  16160.  
  16161.                Copyright c 1991 IEEE.  All rights reserved.
  16162.       This is an unapproved IEEE Standards Draft, subject to change.
  16163.  
  16164.  
  16165.  
  16166.  
  16167.  
  16168.  3 Shell Command Language                                              215
  16169.  
  16170.  
  16171.  
  16172.  
  16173.  
  16174.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16175.  
  16176.  3.0.1  Shell Command Language Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  16177.         _P_1_0_0_3._2)
  16178.  
  16179.  The System V shell was selected as the starting point for this standard.
  16180.  The BSD C-shell was excluded from consideration, for the following
  16181.  reasons:
  16182.  
  16183.      (1)  Most historically portable shell scripts assume the Version 7
  16184.           ``Bourne'' shell, from which the System V shell is derived.
  16185.  
  16186.      (2)  The majority of tutorial materials on shell programming assume
  16187.           the System V shell.
  16188.  
  16189.  Despite the selection of the System V shell, the developers of the
  16190.  standard did not limit the possibilities for a shell command language
  16191.  that was upward-compatible.
  16192.  
  16193.  The only programmatic interfaces to the shell language are through the
  16194.  functions in 7.1 and the sh utility.  Most implementations provide an
  16195.  interface to, and processing mode for, the shell that is suitable for
  16196.  direct user interaction.  The behavior of this interactive mode is not
  16197.  defined by this standard; however, places where historically an
  16198.  interactive shell behaves differently from the behavior described here
  16199.  are noted.
  16200.  
  16201.      (1)  Aliases are not included in the base POSIX.2 because they
  16202.           duplicate functionality already available to applications with
  16203.           functions.  In early drafts, the search order of simple command
  16204.           lookup was ``aliases, built-ins, functions, file system,'' and
  16205.           therefore an alias was necessary to create a user-defined
  16206.           command having the same name as a built-in.  To retain this
  16207.           capability, the search order has changed to ``special built-ins,
  16208.           functions, built-ins, file system,'' and a built-in, called
  16209.           command, has been added, which disables the looking up of
  16210.           functions.  Aliases are a part of the POSIX.2a UPE because they
  16211.           are widely used by human users, as differentiated from
  16212.           applications.
  16213.  
  16214.      (2)  All references to job control and related commands have been
  16215.           omitted from the base POSIX.2.  POSIX.2 describes the
  16216.           noninteractive operation of the shell; job control is outside
  16217.           the scope of this standard until the UPE revision is developed.
  16218.           Apparently it is not widely known that traditionally, even in a
  16219.           job control environment, the commands executed during the
  16220.           execution of a shell script are not placed into separate process
  16221.           groups.  If they were, one could not stop the execution of the
  16222.           shell script from the interactive shell, for example.  This
  16223.           standard does not require or prohibit job control; it simply
  16224.           does not mention it.
  16225.  
  16226.  
  16227.                Copyright c 1991 IEEE.  All rights reserved.
  16228.       This is an unapproved IEEE Standards Draft, subject to change.
  16229.  
  16230.  
  16231.  
  16232.  
  16233.  
  16234.  216                                              3 Shell Command Language
  16235.  
  16236.  
  16237.  
  16238.  
  16239.  
  16240.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16241.  
  16242.      (3)  The conditional command (double bracket [[ ]]) was removed from
  16243.           an earlier draft.  Objections were lodged that the real problem
  16244.           is misuse of the test command ([), and putting it into the shell
  16245.           is the wrong way to fix the problem.  Instead, proper
  16246.           documentation and a new shell reserved word (!) are sufficient.
  16247.           Tests that require multiple test operations can be done at the
  16248.           shell level using individual invocations of the test command and
  16249.           shell logicals, rather than the error prone -o flag of test.
  16250.  
  16251.      (4)  Exportable functions were removed from an earlier draft.  See
  16252.           the rationale in 3.9.5.1.
  16253.  
  16254.  The construct #! is reserved for implementations wishing to provide that
  16255.  extension.  If it were not reserved, the standard would disallow it by
  16256.  forcing it to be a comment.  As it stands, a conforming application shall
  16257.  not use #!  as the first line of a shell script.
  16258.  
  16259.  END_RATIONALE
  16260.  
  16261.  
  16262.  
  16263.  3.1  Shell Definitions
  16264.  
  16265.  The following terms are used in Section 3.  Because they are specific to
  16266.  the shell, they do not appear in 2.2.2.
  16267.  
  16268.  3.1.1  control operator:  A token that performs a control function.
  16269.  
  16270.  It is one of the following symbols:
  16271.  
  16272.                          &           )       <newline>
  16273.                         &&           ;           |
  16274.                          (          ;;          ||
  16275.  
  16276.  The end-of-input indicator used internally by the shell is also
  16277.  considered a control operator.  See 3.3.
  16278.  
  16279.  On some systems, the symbol (( is a control operator; its use produces     1
  16280.  unspecified results.
  16281.  
  16282.  3.1.2  expand:  When not qualified, the act of applying all the
  16283.  expansions described in 3.6.
  16284.  
  16285.  3.1.3  field:  A unit of text that is the result of parameter expansion
  16286.  (3.6.2), arithmetic expansion (3.6.4), command substitution (3.6.3), or
  16287.  field splitting (3.6.5).
  16288.  
  16289.  During command processing (see 3.9.1), the resulting fields are used as
  16290.  the command name and its arguments.
  16291.  
  16292.  
  16293.                Copyright c 1991 IEEE.  All rights reserved.
  16294.       This is an unapproved IEEE Standards Draft, subject to change.
  16295.  
  16296.  
  16297.  
  16298.  
  16299.  
  16300.  3.1 Shell Definitions                                                 217
  16301.  
  16302.  
  16303.  
  16304.  
  16305.  
  16306.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16307.  
  16308.  3.1.4  interactive shell:  A processing mode of the shell that is
  16309.  suitable for direct user interaction.
  16310.  
  16311.  The behavior in this mode is not defined by this standard.
  16312.  
  16313.  NOTE:  The preceding sentence is expected to change following the
  16314.  eventual approval of the UPE supplement.
  16315.  
  16316.  3.1.5  name:  A word consisting solely of underscores, digits, and
  16317.  alphabetics from the portable character set (see 2.4).
  16318.  
  16319.  The first character of a name shall not be a digit.
  16320.  
  16321.  3.1.6  operator:  Either a control operator or a redirection operator.
  16322.  
  16323.  3.1.7  parameter:  An entity that stores values.
  16324.  
  16325.  There are three types of parameters:  variables (named parameters),
  16326.  positional parameters, and special parameters.  Parameter expansion is
  16327.  accomplished by introducing a parameter with the $ character.  See 3.5.
  16328.  
  16329.  3.1.8  positional parameter:  A parameter denoted by a single digit or
  16330.  one or more digits in curly braces.
  16331.  
  16332.  See 3.5.1.
  16333.  
  16334.  3.1.9  redirection:  A method of associating files with the input/output
  16335.  of commands.
  16336.  
  16337.  See 3.7.
  16338.  
  16339.  3.1.10  redirection operator:  A token that performs a redirection
  16340.  function.
  16341.  
  16342.  It is one of the following symbols:
  16343.  
  16344.        <     >     >|     <<     >>     <&     >&     <<-     <>
  16345.  
  16346.  3.1.11  special parameter:  A parameter named by a single character from
  16347.  the following list:
  16348.  
  16349.        *         @         #         ?         !         -         $        0
  16350.  
  16351.  See 3.5.2.
  16352.  
  16353.  3.1.12  subshell:  A shell execution environment, distinguished from the
  16354.  main or current shell execution environment by the attributes described
  16355.  in 3.12.
  16356.  
  16357.  
  16358.  
  16359.                Copyright c 1991 IEEE.  All rights reserved.
  16360.       This is an unapproved IEEE Standards Draft, subject to change.
  16361.  
  16362.  
  16363.  
  16364.  
  16365.  
  16366.  218                                              3 Shell Command Language
  16367.  
  16368.  
  16369.  
  16370.  
  16371.  
  16372.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16373.  
  16374.  3.1.13  token:  A sequence of characters that the shell considers as a
  16375.  single unit when reading input, according to the rules in 3.3.
  16376.  
  16377.  A token is either an operator or a word.
  16378.  
  16379.  3.1.14  variable:  A named parameter.  See 3.5.
  16380.  
  16381.  3.1.15  variable assignment [assignment]:  A word consisting of the
  16382.  following parts
  16383.  
  16384.        _v_a_r_n_a_m_e=_v_a_l_u_e
  16385.  
  16386.  When used in a context where assignment is defined to occur (see 3.9.1)
  16387.  and at no other time, the _v_a_l_u_e (representing a word or field) shall be
  16388.  assigned as the value of the variable denoted by _v_a_r_n_a_m_e. The _v_a_r_n_a_m_e and
  16389.  _v_a_l_u_e parts meet the requirements for a name and a word, respectively,
  16390.  except that they are delimited by the embedded unquoted equals-sign in
  16391.  addition to the delimiting described in 3.3.  In all cases, the variable
  16392.  shall be created if it did not already exist.  If _v_a_l_u_e is not specified,
  16393.  the variable shall be given a null value.
  16394.  
  16395.  An alternative form of variable assignment:
  16396.  
  16397.        _s_y_m_b_o_l=_v_a_l_u_e
  16398.  
  16399.  (where _s_y_m_b_o_l is a valid word delimited by an equals-sign, but not a
  16400.  valid name) produces unspecified results.
  16401.  
  16402.  3.1.16  word:  A token other than an operator.
  16403.  
  16404.  In some cases a word is also a portion of a word token:  in the various
  16405.  forms of parameter expansion (3.6.2), such as ${_n_a_m_e-_w_o_r_d}, and variable
  16406.  assignment, such as _n_a_m_e=_w_o_r_d, the word is the portion of the token
  16407.  depicted by _w_o_r_d. The concept of a word is no longer applicable following
  16408.  word expansions--only fields remain; see 3.6.
  16409.  
  16410.  BEGIN_RATIONALE
  16411.  
  16412.  
  16413.  3.1.17  Shell Definitions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  16414.          _P_1_0_0_3._2)
  16415.  
  16416.  The _w_o_r_d=_w_o_r_d form of variable assignment was included, producing
  16417.  unspecified results, to allow the KornShell _n_a_m_e[_e_x_p_r_e_s_s_i_o_n]=_v_a_l_u_e syntax
  16418.  to conform.
  16419.  
  16420.  The (( symbol is a control operator in the KornShell, used for an          1
  16421.  alternative syntax of an arithmetic expression command.  A strictly
  16422.  conforming POSIX.2 application cannot use (( as a single token [with the
  16423.  
  16424.  
  16425.                Copyright c 1991 IEEE.  All rights reserved.
  16426.       This is an unapproved IEEE Standards Draft, subject to change.
  16427.  
  16428.  
  16429.  
  16430.  
  16431.  
  16432.  3.1 Shell Definitions                                                 219
  16433.  
  16434.  
  16435.  
  16436.  
  16437.  
  16438.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16439.  
  16440.  obvious exception of the $(( form described in POSIX.2].  The decision to
  16441.  require this is based solely on the pragmatic knowledge that there are
  16442.  many more historical shell scripts using the KornShell syntax than there
  16443.  might be using nested subshells, such as
  16444.  
  16445.        ((foo))       or        ((foo);(bar))
  16446.  
  16447.  The latter example should not be misinterpreted by the shell as
  16448.  arithmetic because attempts to balance the parentheses pairs would
  16449.  indicate that they are subshells.  Thus, in most cases, while a few
  16450.  scripts will no longer be strictly portable, the chances of breaking
  16451.  existing scripts is even smaller.
  16452.  
  16453.  There are no explicit limits in this standard on the sizes of names,       1
  16454.  words, lines, or other objects.  However, other implicit limits do apply:  1
  16455.  shell script lines produced by many of the standard utilities cannot       1
  16456.  exceed {LINE_MAX} and the sum of exported variables comes under the        1
  16457.  {ARG_MAX} limit.  Historical shells dynamically allocate memory for names  1
  16458.  and words and parse incoming lines a byte at a time.  Lines cannot have    1
  16459.  an arbitrary {LINE_MAX} limit because of historical practice such as       1
  16460.  makefiles, where make removes the <newline>s associated with the commands  1
  16461.  for a target and presents the shell with one very long line.  The text in  1
  16462.  2.11.5.2 does allow a shell to run out of memory, but it cannot have
  16463.  arbitrary programming limits.
  16464.  
  16465.  END_RATIONALE
  16466.  
  16467.  
  16468.  
  16469.  3.2  Quoting
  16470.  
  16471.  Quoting is used to remove the special meaning of certain characters or
  16472.  words to the shell.  Quoting can be used to preserve the literal meaning
  16473.  of the special characters in the next paragraph; prevent reserved words
  16474.  from being recognized as such; and prevent parameter expansion and
  16475.  command substitution within here-document processing (see 3.7.4).
  16476.  
  16477.  The following characters shall be quoted if they are to represent
  16478.  themselves:
  16479.  
  16480.        |    &    ;    <    >    (    )    $    `    \    "    '
  16481.        <space>    <tab>    <newline>
  16482.  
  16483.  and the following may need to be quoted under certain circumstances.
  16484.  That is, these characters may be special depending on conditions
  16485.  described elsewhere in the standard:
  16486.  
  16487.        *          ?          [          #          ~          =          %
  16488.  
  16489.  
  16490.  
  16491.                Copyright c 1991 IEEE.  All rights reserved.
  16492.       This is an unapproved IEEE Standards Draft, subject to change.
  16493.  
  16494.  
  16495.  
  16496.  
  16497.  
  16498.  220                                              3 Shell Command Language
  16499.  
  16500.  
  16501.  
  16502.  
  16503.  
  16504.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16505.  
  16506.  The various quoting mechanisms are the escape character, single-quotes,
  16507.  and double-quotes.  The here-document represents another form of quoting;
  16508.  see 3.7.4.
  16509.  
  16510.  
  16511.  3.2.1  Escape Character (Backslash)
  16512.  
  16513.  A backslash that is not quoted shall preserve the literal value of the
  16514.  following character, with the exception of a <newline>.  If a <newline>
  16515.  follows the backslash, the shell shall interpret this as line
  16516.  continuation.  The backslash and <newline> shall be removed before
  16517.  splitting the input into tokens.
  16518.  
  16519.  
  16520.  3.2.2  Single-Quotes
  16521.  
  16522.  Enclosing characters in single-quotes (' ') shall preserve the literal
  16523.  value of each character within the single-quotes.  A single-quote cannot
  16524.  occur within single-quotes.
  16525.  
  16526.  
  16527.  3.2.3  Double-Quotes
  16528.  
  16529.  Enclosing characters in double-quotes (" ") shall preserve the literal
  16530.  value of all characters within the double-quotes, with the exception of
  16531.  the characters dollar-sign, backquote, and backslash, as follows:
  16532.  
  16533.     $     The dollar-sign shall retain its special meaning introducing
  16534.           parameter expansion (see 3.6.2), a form of command substitution
  16535.           (see 3.6.3), and arithmetic expansion (see 3.6.4).
  16536.  
  16537.           The input characters within the quoted string that are also
  16538.           enclosed between $( and the matching ) shall not be affected by
  16539.           the double-quotes, but rather shall define that command whose
  16540.           output replaces the $(...) when the word is expanded.  The
  16541.           tokenizing rules in 3.3 shall be applied recursively to find the
  16542.           matching ).
  16543.  
  16544.           Within the string of characters from an enclosed ${ to the
  16545.           matching }, an even number of unescaped double-quotes or
  16546.           single-quotes, if any, shall occur.  A preceding backslash
  16547.           character shall be used to escape a literal { or }.  The rule in
  16548.           3.6.2 shall be used to determine the matching }.
  16549.  
  16550.     `     The backquote shall retain its special meaning introducing the
  16551.           other form of command substitution (see 3.6.3).  The portion of
  16552.           the quoted string from the initial backquote and the characters
  16553.           up to the next backquote that is not preceded by a backslash,
  16554.           having escape characters removed, defines that command whose
  16555.  
  16556.  
  16557.                Copyright c 1991 IEEE.  All rights reserved.
  16558.       This is an unapproved IEEE Standards Draft, subject to change.
  16559.  
  16560.  
  16561.  
  16562.  
  16563.  
  16564.  3.2 Quoting                                                           221
  16565.  
  16566.  
  16567.  
  16568.  
  16569.  
  16570.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16571.  
  16572.           output replaces `...` when the word is expanded.  Either of the
  16573.           following cases produces undefined results:
  16574.  
  16575.            - A single- or double-quoted string that begins, but does not
  16576.              end, within the `...` sequence.
  16577.  
  16578.            - A `...` sequence that begins, but does not end, within the
  16579.              same double-quoted string.
  16580.  
  16581.     \     The backslash shall retain its special meaning as an escape
  16582.           character (see 3.2.1) only when followed by one of the
  16583.           characters:
  16584.  
  16585.                 $     `     "     \     <newline>
  16586.  
  16587.  A double-quote shall be preceded by a backslash to be included within
  16588.  double-quotes.  The parameter @ has special meaning inside double-quotes
  16589.  and is described in 3.5.2.
  16590.  
  16591.  BEGIN_RATIONALE
  16592.  
  16593.  
  16594.  3.2.4  Quotes Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  16595.  
  16596.  A backslash cannot be used to escape a single-quote in a single-quoted
  16597.  string.  An embedded quote can be created by writing, for example,
  16598.  'a'\''b', which yields a'b.  (See 3.6.5 for a better understanding of how
  16599.  portions of words are either split into fields or remain concatenated.)
  16600.  A single token can be made up of concatenated partial strings containing
  16601.  all three kinds of quoting/escaping, thus permitting any combination of
  16602.  characters.
  16603.  
  16604.  The escaped <newline> used for line continuation is removed entirely from
  16605.  the input and is not replaced by any white space.  Therefore, it cannot
  16606.  serve as a token separator.
  16607.  
  16608.  In double-quoting, if a backslash is immediately followed by a character
  16609.  that would be interpreted as having a special meaning, the backslash is
  16610.  deleted and the subsequent character is taken literally.  If a backslash
  16611.  does not precede a character that would have a special meaning, it is
  16612.  left in place unmodified and the character immediately following it is
  16613.  also left unmodified.  Thus, for example:
  16614.  
  16615.        "\$"   =>   $
  16616.  
  16617.        "\a"   =>   \a
  16618.  
  16619.  It would be desirable to include the statement ``The characters from an
  16620.  enclosed ${ to the matching } shall not be affected by the double-
  16621.  
  16622.  
  16623.                Copyright c 1991 IEEE.  All rights reserved.
  16624.       This is an unapproved IEEE Standards Draft, subject to change.
  16625.  
  16626.  
  16627.  
  16628.  
  16629.  
  16630.  222                                              3 Shell Command Language
  16631.  
  16632.  
  16633.  
  16634.  
  16635.  
  16636.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16637.  
  16638.  quotes,'' similar to the one for $( ).  However, historical practice in
  16639.  the System V shell prevents this.  The requirement that double-quotes be
  16640.  matched inside ${...} within double-quotes and the rule for finding the
  16641.  matching } in 3.6.2 eliminate several subtle inconsistencies in expansion
  16642.  for historical shells in rare cases; for example,
  16643.  
  16644.        "${foo-bar"}
  16645.  
  16646.  yields bar when foo is not defined, and is an invalid substitution when    1
  16647.  foo is defined, in many historical shells.  The differences in processing
  16648.  the "${...}" form have led to inconsistencies between the historical
  16649.  System V, BSD, and KornShells, and the text in POSIX.2 is an attempt to
  16650.  converge them without breaking many applications.  A consequence of the
  16651.  new rule is that single-quotes cannot be used to quote the } within
  16652.  "${...}"; for example
  16653.  
  16654.        unset bar
  16655.        foo="${bar-'}'}"
  16656.  
  16657.  is invalid because the "${...}" substitution contains an unpaired          1
  16658.  unescaped single-quote.  The backslash can be used to escape the } in      1
  16659.  this example to achieve the desired result:
  16660.  
  16661.        unset bar
  16662.        foo="${bar-\}}"
  16663.  
  16664.  The only alternative to this compromise between shells would be to make
  16665.  the behavior unspecified whenever the literal characters ', {, }, and "
  16666.  appear within ${...}.  To write a portable script that uses these values,
  16667.  a user would have to assign variables, say,
  16668.  
  16669.        squote=\' dquote=\" lbrace='{' rbrace='}'
  16670.        ${foo-$squote$rbrace$squote}
  16671.  
  16672.  rather than
  16673.  
  16674.        ${foo-"'}'"}
  16675.  
  16676.  Some systems have allowed the end of the word to terminate the backquoted
  16677.  command substitution, such as in
  16678.  
  16679.        "`echo hello"
  16680.  
  16681.  This usage is undefined in POSIX.2, where the matching backquote is
  16682.  required.  The other undefined usage can be illustrated by the example:
  16683.  
  16684.        sh -c '` echo "foo`'
  16685.  
  16686.  
  16687.  
  16688.  
  16689.                Copyright c 1991 IEEE.  All rights reserved.
  16690.       This is an unapproved IEEE Standards Draft, subject to change.
  16691.  
  16692.  
  16693.  
  16694.  
  16695.  
  16696.  3.2 Quoting                                                           223
  16697.  
  16698.  
  16699.  
  16700.  
  16701.  
  16702.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16703.  
  16704.  The description of the recursive actions involving command substitution
  16705.  can be illustrated with an example.  Upon recognizing the introduction of
  16706.  command substitution, the shell must parse input (in a new context),
  16707.  gathering the ``source'' for the command substitution until an unbalanced
  16708.  ) or ` is located.  For example, in the following
  16709.  
  16710.        echo "$(date; echo "
  16711.                one" )"
  16712.  
  16713.  the double-quote following the echo does not terminate the first double-
  16714.  quote; it is part of the command substitution ``script.''  Similarly, in
  16715.  
  16716.        echo "$(echo *)"
  16717.  
  16718.  the asterisk is not quoted since it is inside command substitution;
  16719.  however,
  16720.  
  16721.        echo "$(echo "*")"
  16722.  
  16723.  is quoted (and represents the asterisk character itself).
  16724.  
  16725.  END_RATIONALE
  16726.  
  16727.  
  16728.  
  16729.  3.3  Token Recognition
  16730.  
  16731.  The shell reads its input in terms of lines from a file, from a terminal
  16732.  in the case of an interactive shell, or from a string in the case of
  16733.  sh -c or _s_y_s_t_e_m().  The input lines can be of unlimited length.  These     1
  16734.  lines are parsed using two major modes:  ordinary token recognition and    1
  16735.  processing of here-documents.
  16736.  
  16737.  When an io_here token has been recognized by the grammar (see 3.10), one
  16738.  or more of the immediately subsequent lines form the body of one or more
  16739.  here-documents and shall be parsed according to the rules of 3.7.4.
  16740.  
  16741.  When it is not processing an io_here, the shell shall break its input      1
  16742.  into tokens by applying the first applicable rule below to the next
  16743.  character in its input.  The token shall be from the current position in
  16744.  the input until a token is delimited according to one of the rules below;
  16745.  the characters forming the token are exactly those in the input,
  16746.  including any quoting characters.  If it is indicated that a token is
  16747.  delimited, and no characters have been included in a token, processing
  16748.  shall continue until an actual token is delimited.
  16749.  
  16750.      (1)  If the end of input is recognized, the current token shall be
  16751.           delimited.  If there is no current token, the end-of-input
  16752.           indicator shall be returned as the token.
  16753.  
  16754.  
  16755.                Copyright c 1991 IEEE.  All rights reserved.
  16756.       This is an unapproved IEEE Standards Draft, subject to change.
  16757.  
  16758.  
  16759.  
  16760.  
  16761.  
  16762.  224                                              3 Shell Command Language
  16763.  
  16764.  
  16765.  
  16766.  
  16767.  
  16768.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16769.  
  16770.      (2)  If the previous character was used as part of an operator and
  16771.           the current character is not quoted and can be used with the
  16772.           current characters to form an operator, it shall be used as part
  16773.           of that (operator) token.
  16774.  
  16775.      (3)  If the previous character was used as part of an operator and
  16776.           the current character cannot be used with the current characters
  16777.           to form an operator, the operator containing the previous
  16778.           character shall be delimited.
  16779.  
  16780.      (4)  If the current character is backslash, single-quote, or double-
  16781.           quote (\, ', or ") and it is not quoted, it shall affect quoting
  16782.           for subsequent character(s) up to the end of the quoted text.
  16783.           The rules for quoting are as described in 3.2.  During token
  16784.           recognition no substitutions shall be actually performed, and
  16785.           the result token shall contain exactly the characters that
  16786.           appear in the input (except for <newline> joining), unmodified,
  16787.           including any embedded or enclosing quotes or substitution
  16788.           operators, between the quote mark and the end of the quoted
  16789.           text.  The token shall not be delimited by the end of the quoted
  16790.           field.
  16791.  
  16792.      (5)  If the current character is an unquoted $ or `, the shell shall
  16793.           identify the start of any candidates for parameter expansion
  16794.           (3.6.2), command substitution (3.6.3), or arithmetic expansion
  16795.           (3.6.4) from their introductory unquoted character sequences:  $
  16796.           or ${, $( or `, and $((, respectively.  The shell shall read
  16797.           sufficient input to determine the end of the unit to be expanded
  16798.           (as explained in the cited subclauses).  While processing the
  16799.           characters, if instances of expansions or quoting are found
  16800.           nested within the substitution, the shell shall recursively
  16801.           process them in the manner specified for the construct that is
  16802.           found.  The characters found from the beginning of the
  16803.           substitution to its end, allowing for any recursion necessary to
  16804.           recognize embedded constructs, shall be included unmodified in
  16805.           the result token, including any embedded or enclosing
  16806.           substitution operators or quotes.  The token shall not be
  16807.           delimited by the end of the substitution.
  16808.  
  16809.      (6)  If the current character is not quoted and can be used as the
  16810.           first character of a new operator, the current token (if any)
  16811.           shall be delimited.  The current character shall be used as the
  16812.           beginning of the next (operator) token.
  16813.  
  16814.      (7)  If the current character is an unquoted <newline>, the current
  16815.           token shall be delimited.
  16816.  
  16817.      (8)  If the current character is an unquoted <blank>, any token
  16818.           containing the previous character is delimited and the current
  16819.  
  16820.  
  16821.                Copyright c 1991 IEEE.  All rights reserved.
  16822.       This is an unapproved IEEE Standards Draft, subject to change.
  16823.  
  16824.  
  16825.  
  16826.  
  16827.  
  16828.  3.3 Token Recognition                                                 225
  16829.  
  16830.  
  16831.  
  16832.  
  16833.  
  16834.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16835.  
  16836.           character is discarded.
  16837.  
  16838.      (9)  If the previous character was part of a word, the current
  16839.           character is appended to that word.
  16840.  
  16841.     (10)  If the current character is a #, it and all subsequent
  16842.           characters up to, but excluding, the next <newline> are
  16843.           discarded as a comment.  The <newline> that ends the line is not
  16844.           considered part of the comment.
  16845.  
  16846.     (11)  The current character is used as the start of a new word.
  16847.  
  16848.  Once a token is delimited, it shall be categorized as required by the
  16849.  grammar in 3.10.
  16850.  
  16851.  BEGIN_RATIONALE
  16852.  
  16853.  
  16854.  3.3.1  Token Recognition Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  16855.         _P_1_0_0_3._2)
  16856.  
  16857.  The (3) rule about combining characters to form operators is not meant to  1
  16858.  preclude systems from extending the shell language when characters are     1
  16859.  combined in otherwise invalid ways.  Portable applications cannot use      1
  16860.  invalid combinations and test suites should not penalize systems that      1
  16861.  take advantage of this fact.  For example, the unquoted combination |& is  1
  16862.  not valid in a POSIX.2 script, but has a specific KornShell meaning.       1
  16863.  
  16864.  The (10) rule about # as the current character is the first in the
  16865.  sequence in which a new token is being assembled.  The # starts a comment
  16866.  only when it is at the beginning of a token.  This rule is also written
  16867.  to indicate that the search for the end-of-comment does not consider
  16868.  escaped <newline> specially, so that a comment cannot be continued to the
  16869.  next line.
  16870.  
  16871.  END_RATIONALE
  16872.  
  16873.  
  16874.  
  16875.  3.4  Reserved Words
  16876.  
  16877.  Reserved words are words that have special meaning to the shell.  (See
  16878.  3.9.)  The following words shall be recognized as reserved words:
  16879.  
  16880.                    !       elif    fi      in      while
  16881.                    case    else    for     then    {4)
  16882.                    do      esac    if      until   }
  16883.                    done
  16884.  
  16885.  
  16886.  
  16887.                Copyright c 1991 IEEE.  All rights reserved.
  16888.       This is an unapproved IEEE Standards Draft, subject to change.
  16889.  
  16890.  
  16891.  
  16892.  
  16893.  
  16894.  226                                              3 Shell Command Language
  16895.  
  16896.  
  16897.  
  16898.  
  16899.  
  16900.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  16901.  
  16902.  This recognition shall occur only when none of the characters are quoted
  16903.  and when the word is used as:
  16904.  
  16905.      (1)  The first word of a command
  16906.  
  16907.      (2)  The first word following one of the reserved words other than
  16908.           case, for, or in
  16909.  
  16910.      (3)  The third word in a case or for command (only in is valid in
  16911.           this case)
  16912.  
  16913.  See the grammar in 3.10.
  16914.  
  16915.  The following words may be recognized as reserved words on some systems
  16916.  (when none of the characters are quoted), causing unspecified results:
  16917.  
  16918.                  function   select     [[         ]]                        2
  16919.  
  16920.  Words that are the concatenation of a name and a colon (:) are reserved;
  16921.  their use produces unspecified results.
  16922.  
  16923.  BEGIN_RATIONALE
  16924.  
  16925.  
  16926.  3.4.1  Reserved Words Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  16927.         _P_1_0_0_3._2)
  16928.  
  16929.  All reserved words are recognized syntactically as such in the contexts
  16930.  described.  However, it is useful to point out that in is the only
  16931.  meaningful reserved word after a case or for; similarly, in is not
  16932.  meaningful as the first word of a simple command.
  16933.  
  16934.  Reserved words are recognized only when they are delimited (i.e., meet
  16935.  the definition of _w_o_r_d; see 3.1.16), whereas operators are themselves
  16936.  delimiters.  For instance, ( and ) are control operators, so that no
  16937.  <space> is needed in (list).  However, { and } are reserved words in
  16938.  { list;}, so that in this case the leading <space> and semicolon are
  16939.  required.
  16940.  
  16941.  
  16942.  
  16943.  __________
  16944.   4) In some historical systems, the curly braces are treated as control
  16945.      operators.  To assist in future standardization activities, portable
  16946.      applications should avoid using unquoted braces to represent the
  16947.      characters themselves.  It is possible that a future version of
  16948.      POSIX.2 may require this, although probably not for the often-used
  16949.      find {} construct.
  16950.  
  16951.  
  16952.  
  16953.                Copyright c 1991 IEEE.  All rights reserved.
  16954.       This is an unapproved IEEE Standards Draft, subject to change.
  16955.  
  16956.  
  16957.  
  16958.  
  16959.  
  16960.  3.4 Reserved Words                                                    227
  16961.  
  16962.  
  16963.  
  16964.  
  16965.  
  16966.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  16967.  
  16968.  The list of unspecified reserved words is from the KornShell, so portable
  16969.  applications cannot use them in places a reserved word would be
  16970.  recognized.  This list contained time in earlier drafts, but it was        2
  16971.  removed when the time utility was selected for the UPE.                    2
  16972.  
  16973.  There was a strong argument for promoting braces to operators (instead of
  16974.  reserved words), so they would be syntactically equivalent to subshell
  16975.  operators.  Concerns about compatibility outweighed the advantages of
  16976.  this approach.  Nevertheless, portable applications should consider
  16977.  quoting { and } when they represent themselves.
  16978.  
  16979.  The restriction on ending a name with a colon is to allow future
  16980.  implementations that support named labels for flow control.  See the
  16981.  rationale for break (3.14.1.1).
  16982.  
  16983.  END_RATIONALE
  16984.  
  16985.  
  16986.  
  16987.  3.5  Parameters and Variables
  16988.  
  16989.  A parameter can be denoted by a name, a number, or one of the special
  16990.  characters listed in 3.5.2.  A variable is a parameter denoted by a name.
  16991.  
  16992.  A parameter is set if it has an assigned value (null is a valid value).
  16993.  Once a variable is set, it can only be unset by using the unset special
  16994.  built-in command.
  16995.  
  16996.  
  16997.  3.5.1  Positional Parameters
  16998.  
  16999.  A positional parameter is a parameter denoted by the decimal value
  17000.  represented by one or more digits, other than the single digit 0.  When a
  17001.  positional parameter with more than one digit is specified, the
  17002.  application shall enclose the digits in braces (see 3.6.2).  Positional
  17003.  parameters are initially assigned when the shell is invoked (see sh in
  17004.  4.56), temporarily replaced when a shell function is invoked (see 3.9.5),
  17005.  and can be reassigned with the set special built-in command.
  17006.  
  17007.  BEGIN_RATIONALE
  17008.  
  17009.  3.5.1.1  Positional Parameters Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t
  17010.           _o_f _P_1_0_0_3._2)
  17011.  
  17012.  The digits denoting the positional parameters are always interpreted as a
  17013.  decimal value, even if there is a leading zero.
  17014.  
  17015.  END_RATIONALE
  17016.  
  17017.  
  17018.  
  17019.                Copyright c 1991 IEEE.  All rights reserved.
  17020.       This is an unapproved IEEE Standards Draft, subject to change.
  17021.  
  17022.  
  17023.  
  17024.  
  17025.  
  17026.  228                                              3 Shell Command Language
  17027.  
  17028.  
  17029.  
  17030.  
  17031.  
  17032.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17033.  
  17034.  3.5.2  Special Parameters
  17035.  
  17036.  Listed below are the special parameters and the values to which they
  17037.  shall expand.  Only the values of the special parameters are listed; see
  17038.  3.6 for a detailed summary of all the stages involved in expanding words.
  17039.  
  17040.     *     Expands to the positional parameters, starting from one.  When
  17041.           the expansion occurs within a double-quoted string (see 3.2.3),
  17042.           it expands to a single field with the value of each parameter
  17043.           separated by the first character of the IFS variable, or by a
  17044.           <space> if IFS is unset.
  17045.  
  17046.     @     Expands to the positional parameters, starting from one.  When
  17047.           the expansion occurs within double-quotes, each positional
  17048.           parameter expands as a separate field, with the provision that
  17049.           the expansion of the first parameter is still joined with the
  17050.           beginning part of the original word (assuming that the expanded
  17051.           parameter was embedded within a word), and the expansion of the
  17052.           last parameter is still joined with the last part of the
  17053.           original word.  If there are no positional parameters, the        1
  17054.           expansion of @ shall generate zero fields, even when @ is         1
  17055.           double-quoted.                                                    1
  17056.  
  17057.     #     Expands to the decimal number of positional parameters.
  17058.  
  17059.     ?     Expands to the decimal exit status of the most recent pipeline
  17060.           (see 3.9.2).
  17061.  
  17062.     -     (Hyphen) Expands to the current option flags (the single-letter
  17063.           option names concatenated into a string) as specified on
  17064.           invocation, by the set special built-in command, or implicitly
  17065.           by the shell.
  17066.  
  17067.     $     Expands to the decimal process ID of the invoked shell.  In a
  17068.           subshell (see 3.12), $ shall expand to the same value as that of
  17069.           the current shell.
  17070.  
  17071.     !     Expands to the decimal process ID of the most recent background
  17072.           command (see 3.9.3) executed from the current shell.  For a       1
  17073.           pipeline, the process ID is that of the last command in the
  17074.           pipeline.
  17075.  
  17076.     0     (Zero.)  Expands to the name of the shell or shell script.  See
  17077.           sh (4.56) for a detailed description of how this name is
  17078.           derived.
  17079.  
  17080.  See the description of the IFS variable in 3.5.3.
  17081.  
  17082.  
  17083.  
  17084.  
  17085.                Copyright c 1991 IEEE.  All rights reserved.
  17086.       This is an unapproved IEEE Standards Draft, subject to change.
  17087.  
  17088.  
  17089.  
  17090.  
  17091.  
  17092.  3.5 Parameters and Variables                                          229
  17093.  
  17094.  
  17095.  
  17096.  
  17097.  
  17098.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17099.  
  17100.  BEGIN_RATIONALE
  17101.  
  17102.  
  17103.  3.5.2.1  Special Parameters Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  17104.           _P_1_0_0_3._2)
  17105.  
  17106.  Most historical implementations implement subshells by forking; thus, the
  17107.  special parameter $ does not necessarily represent the process ID of the
  17108.  shell process executing the commands since the subshell execution
  17109.  environment preserves the value of $.
  17110.  
  17111.  If a subshell were to execute a background command, the value of its       1
  17112.  parent's $! would not change.  For example:                                1
  17113.  
  17114.        (                                                                    1
  17115.        date &                                                               1
  17116.        echo $!                                                              1
  17117.        )                                                                    1
  17118.        echo $!                                                              1
  17119.  
  17120.  would echo two different values for $!.                                    1
  17121.  
  17122.  The descriptions of parameters * and @ assume the reader is familiar with
  17123.  the field splitting discussion in 3.6.5 and understands that portions of
  17124.  the word will remain concatenated unless there is some reason to split
  17125.  them into separate fields.  Some examples of the * and @ properties,
  17126.  including the concatenation aspects:
  17127.  
  17128.        set "abc" "def ghi" "jkl"
  17129.  
  17130.        echo $*         => "abc" "def" "ghi" "jkl"
  17131.        echo "$*"       => "abc def ghi jkl"
  17132.        echo $@         => "abc" "def" "ghi" "jkl"
  17133.  
  17134.        _b_u_t
  17135.  
  17136.        echo "$@"       => "abc" "def ghi" "jkl"
  17137.        echo "xx$@yy"   => "xxabc" "def ghi" "jklyy"
  17138.        echo "$@$@"     => "abc" "def ghi" "jklabc" "def ghi" "jkl"
  17139.  
  17140.  In the preceding examples, the double-quote characters that appear after
  17141.  the => do not appear in the output and are used only to illustrate word
  17142.  boundaries.
  17143.  
  17144.  Historical versions of the Bourne shell have used <space> as a separator
  17145.  between the expanded members of "$*".  The KornShell has used the first
  17146.  character in IFS, which is <space> by default.  If IFS is set to a null    1
  17147.  string, this is not equivalent to unsetting it; its first character will   1
  17148.  not exist, so the parameter values are concatenated.  For example:         1
  17149.  
  17150.  
  17151.                Copyright c 1991 IEEE.  All rights reserved.
  17152.       This is an unapproved IEEE Standards Draft, subject to change.
  17153.  
  17154.  
  17155.  
  17156.  
  17157.  
  17158.  230                                              3 Shell Command Language
  17159.  
  17160.  
  17161.  
  17162.  
  17163.  
  17164.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17165.  
  17166.        $ IFS=''                                                             1
  17167.        $ set foo bar bam                                                    1
  17168.        $ echo "$@"                                                          1
  17169.        foo bar bam                                                          1
  17170.        $ echo "$*"                                                          1
  17171.        foobarbam                                                            1
  17172.        $ unset IFS                                                          1
  17173.        $ echo "$*"                                                          1
  17174.        foo bar bam                                                          1
  17175.  
  17176.  The $- can be used to save and restore set options:
  17177.  
  17178.        Save=$(echo $- | sed 's/[ics]//g')                                   1
  17179.        ...
  17180.        set +aCefnuvx                                                        2
  17181.        set -$Save
  17182.  
  17183.  The three options are removed using sed in the example because they may    1
  17184.  appear in the value of $- (from the sh command line), but are not valid    1
  17185.  options to set.                                                            1
  17186.  
  17187.  The command name (parameter 0) is not counted in the number given by #
  17188.  because it is a special parameter, not a positional parameter.
  17189.  
  17190.  END_RATIONALE
  17191.  
  17192.  
  17193.  3.5.3  Variables
  17194.  
  17195.  Variables shall be initialized from the environment (as defined by
  17196.  POSIX.1 {8}) and can be given new values with variable assignment
  17197.  commands.  If a variable is initialized from the environment, it shall be
  17198.  marked for export immediately; see 3.14.8.  New variables can be defined
  17199.  and initialized with variable assignments, with the read or getopts
  17200.  utilities, with the _n_a_m_e parameter in a for loop (see 3.9.4.2), with the
  17201.  ${_n_a_m_e=_w_o_r_d} expansion, or with other mechanisms provided as
  17202.  implementation extensions.  The following variables shall affect the
  17203.  execution of the shell:
  17204.  
  17205.     HOME               This variable shall be interpreted as the pathname
  17206.                        of the user's home directory.  The contents of HOME
  17207.                        are used in Tilde Expansion (see 3.6.1).
  17208.  
  17209.     IFS                _I_n_p_u_t _f_i_e_l_d _s_e_p_a_r_a_t_o_r_s:  a string treated as a list
  17210.                        of characters that is used for field splitting and
  17211.                        to split lines into fields with the read command.
  17212.                        If IFS is not set, the shell shall behave as if the
  17213.                        value of IFS were the <space>, <tab>, and <newline>
  17214.                        characters.  (See 3.6.5.)
  17215.  
  17216.  
  17217.                Copyright c 1991 IEEE.  All rights reserved.
  17218.       This is an unapproved IEEE Standards Draft, subject to change.
  17219.  
  17220.  
  17221.  
  17222.  
  17223.  
  17224.  3.5 Parameters and Variables                                          231
  17225.  
  17226.  
  17227.  
  17228.  
  17229.  
  17230.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17231.  
  17232.     LANG               This variable shall provide a default value for the
  17233.                        LC_* variables, as described in 2.6.
  17234.  
  17235.     LC_ALL             This variable shall interact with the LANG and LC_*
  17236.                        variables as described in 2.6.
  17237.  
  17238.     LC_COLLATE         This variable shall determine the behavior of range
  17239.                        expressions, equivalence classes, and
  17240.                        multicharacter collating elements within pattern
  17241.                        matching.
  17242.  
  17243.     LC_CTYPE           This variable shall determine the interpretation of
  17244.                        sequences of bytes of text data as characters
  17245.                        (e.g., single- versus multibyte characters), which
  17246.                        characters are defined as letters (character class
  17247.                        alpha), and the behavior of character classes
  17248.                        within pattern matching.
  17249.  
  17250.     LC_MESSAGES        This variable shall determine the language in which
  17251.                        messages should be written.
  17252.  
  17253.     PATH               This variable represents a string formatted as
  17254.                        described in 2.6, used to effect command
  17255.                        interpretation.  See 3.9.1.1.                        1
  17256.  
  17257.  BEGIN_RATIONALE
  17258.  
  17259.  
  17260.  3.5.3.1  Variables Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  17261.  
  17262.  A description of PWD (which is automatically set by the KornShell
  17263.  whenever the current working directory changes) was omitted because its
  17264.  functionality is easily reproduced using $(pwd).
  17265.  
  17266.  See the discussion of IFS in 3.6.5.1.
  17267.  
  17268.  Other common environment variables used by historical shells are not
  17269.  specified by this standard, but they should be reserved for the
  17270.  historical uses.  For interactive use, other shell variables are expected
  17271.  to be introduced by the UPE (and this rationale will be updated
  17272.  accordingly):  ENV, FCEDIT, HISTFILE, HISTSIZE, LINENO, PPID, PS1, PS2,
  17273.  PS4.
  17274.  
  17275.  Tilde expansion for components of the PATH in an assignment such as:
  17276.  
  17277.        PATH=~hlj/bin:~dwc/bin:$PATH                                         1
  17278.  
  17279.  is a feature of some historical shells and is allowed by the wording of    1
  17280.  3.6.1.  Note that the tildes are expanded during the assignment to PATH,   1
  17281.  not when PATH is accessed during command search.                           1
  17282.  
  17283.                Copyright c 1991 IEEE.  All rights reserved.
  17284.       This is an unapproved IEEE Standards Draft, subject to change.
  17285.  
  17286.  
  17287.  
  17288.  
  17289.  
  17290.  232                                              3 Shell Command Language
  17291.  
  17292.  
  17293.  
  17294.  
  17295.  
  17296.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17297.  
  17298.  END_RATIONALE                                                              1
  17299.  
  17300.  
  17301.  
  17302.  3.6  Word Expansions
  17303.  
  17304.  This clause describes the various expansions that are performed on words.
  17305.  Not all expansions are performed on every word, as explained in the
  17306.  following subclauses.
  17307.  
  17308.  Tilde expansions, parameter expansions, command substitutions, arithmetic
  17309.  expansions, and quote removals that occur within a single word expand to
  17310.  a single field.  It is only field splitting or pathname expansion that
  17311.  can create multiple fields from a single word.  The single exception to
  17312.  this rule is the expansion of the special parameter @ within double-
  17313.  quotes, as is described in 3.5.2.
  17314.  
  17315.  The order of word expansion shall be as follows:
  17316.  
  17317.      (1)  Tilde Expansion (see 3.6.1), Parameter Expansion (see 3.6.2),     1
  17318.           Command Substitution (see 3.6.3), and Arithmetic Expansion (see
  17319.           3.6.4) shall be performed, beginning to end.  [See item (5) in
  17320.           3.3.]
  17321.  
  17322.      (2)  Field Splitting (see 3.6.5) shall be performed on fields
  17323.           generated by step (1) unless IFS is null.
  17324.  
  17325.      (3)  Pathname Expansion (see 3.6.6) shall be performed, unless set -f
  17326.           is in effect.
  17327.  
  17328.      (4)  Quote Removal (see 3.6.7) shall always be performed last.
  17329.  
  17330.  The expansions described in this clause shall occur in the same shell
  17331.  environment as that in which the command is executed.
  17332.  
  17333.  If the complete expansion appropriate for a word results in an empty
  17334.  field, that empty field shall be deleted from the list of fields that
  17335.  form the completely expanded command, unless the original word contained   1
  17336.  single-quote or double-quote characters.                                   1
  17337.  
  17338.  The $ character is used to introduce parameter expansion, command
  17339.  substitution, or arithmetic evaluation.  If an unquoted $ is followed by
  17340.  a character that is either not numeric, the name of one of the special
  17341.  parameters (see 3.5.2), a valid first character of a variable name, a
  17342.  left curly brace ({), or a left parenthesis, the result is unspecified.
  17343.  
  17344.  BEGIN_RATIONALE
  17345.  
  17346.  
  17347.  
  17348.  
  17349.                Copyright c 1991 IEEE.  All rights reserved.
  17350.       This is an unapproved IEEE Standards Draft, subject to change.
  17351.  
  17352.  
  17353.  
  17354.  
  17355.  
  17356.  3.6 Word Expansions                                                   233
  17357.  
  17358.  
  17359.  
  17360.  
  17361.  
  17362.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17363.  
  17364.  3.6.0.1  Word Expansions Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  17365.           _P_1_0_0_3._2)
  17366.  
  17367.  IFS is used for performing field splitting on the results of parameter
  17368.  and command substitution; it is not used for splitting all fields.
  17369.  Previous versions of the shell used it for splitting all fields during
  17370.  field splitting, but this has severe problems because the shell can no
  17371.  longer parse its own script.  There are also important security
  17372.  implications caused by this behavior.  All useful applications of IFS use
  17373.  it for parsing input of the read utility and for splitting the results of
  17374.  parameter and command substitution.  New versions of the shell have fixed
  17375.  this bug, and POSIX.2 requires the corrected behavior.
  17376.  
  17377.  The rule concerning expansion to a single field requires that if foo=abc
  17378.  and bar=def, that
  17379.  
  17380.        "$foo""$bar"
  17381.  
  17382.  expands to the single field
  17383.  
  17384.        abcdef
  17385.  
  17386.  The rule concerning empty fields can be illustrated by:
  17387.  
  17388.        $ unset foo
  17389.        $ set $foo bar '' xyz "$foo" abc
  17390.        $ for i
  17391.        > do
  17392.        >       echo "-$i-"
  17393.        > done
  17394.        -bar-
  17395.        --
  17396.        -xyz-
  17397.        --
  17398.        -abc-
  17399.  
  17400.  Step (1) indicates that Tilde Expansion, Parameter Expansion, Command      1
  17401.  Substitution, and Arithmetic Expansion are all processed simultaneously
  17402.  as they are scanned.  For example, the following is valid arithmetic:
  17403.  
  17404.        x=1
  17405.        echo $(( $(echo 3)+$x ))
  17406.  
  17407.  An earlier draft stated that Tilde Expansion preceded the other steps,     1
  17408.  but this is not the case in known historical implementations; if it were,  1
  17409.  and a referenced home directory contained a $ character, expansions would  1
  17410.  result within the directory name.                                          1
  17411.  
  17412.  
  17413.  
  17414.  
  17415.                Copyright c 1991 IEEE.  All rights reserved.
  17416.       This is an unapproved IEEE Standards Draft, subject to change.
  17417.  
  17418.  
  17419.  
  17420.  
  17421.  
  17422.  234                                              3 Shell Command Language
  17423.  
  17424.  
  17425.  
  17426.  
  17427.  
  17428.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17429.  
  17430.  END_RATIONALE                                                              1
  17431.  
  17432.  
  17433.  3.6.1  Tilde Expansion
  17434.  
  17435.  A _t_i_l_d_e-_p_r_e_f_i_x consists of an unquoted tilde character at the beginning
  17436.  of a word, followed by all of the characters preceding the first unquoted  2
  17437.  slash in the word, or all the characters in the word if there is no        2
  17438.  slash.  In an assignment (see 3.1.15), multiple tilde prefixes can be      2
  17439.  used:  at the beginning of the word (i.e., following the equals-sign of    2
  17440.  the assignment) and/or following any unquoted colon.  A tilde prefix in    2
  17441.  an assignment is terminated by the first unquoted colon or slash.  If      2
  17442.  none of the characters in the tilde-prefix are quoted, the characters in   1
  17443.  the tilde-prefix following the tilde shall be treated as a possible login  1
  17444.  name from the user database (see POSIX.1 {8} Section 9).  A portable       2
  17445.  login name cannot contain characters outside the set given in the          2
  17446.  description of the LOGNAME environment variable in POSIX.1 {8}.  If the    2
  17447.  login name is null (i.e., the tilde-prefix contains only the tilde), the
  17448.  tilde-prefix shall be replaced by the value of the variable HOME.  If
  17449.  HOME is unset, the results are unspecified.  Otherwise, the tilde-prefix
  17450.  shall be replaced by a pathname of the home directory associated with the
  17451.  login name obtained using the equivalent of the POSIX.1 {8} _g_e_t_p_w_n_a_m()     1
  17452.  function.  If the system does not recognize the login name, the results    1
  17453.  are undefined.
  17454.  
  17455.  BEGIN_RATIONALE
  17456.  
  17457.  
  17458.  3.6.1.1  Tilde Expansion Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  17459.           _P_1_0_0_3._2)
  17460.  
  17461.                                                                             2
  17462.  
  17463.  The text about quoting of the word indicates that \~hlj/, ~h\lj/,          2
  17464.  ~"hlj"/, ~hlj\/, and ~hlj/ are not equivalent: only the last will cause    2
  17465.  tilde expansion.                                                           2
  17466.  
  17467.  Tilde expansion generally occurs only at the beginning of words, but       2
  17468.  POSIX.2 has adopted an exception based on historical practice in the       2
  17469.  KornShell:                                                                 2
  17470.  
  17471.        PATH=/posix/bin:~dgk/bin                                             2
  17472.  
  17473.  is eligible for tilde expansion because tilde follows a colon and none of  2
  17474.  the relevant characters is quoted.  Consideration was given to             2
  17475.  prohibiting this behavior because any of the following are reasonable      2
  17476.  substitutes:                                                               2
  17477.  
  17478.  
  17479.  
  17480.  
  17481.                Copyright c 1991 IEEE.  All rights reserved.
  17482.       This is an unapproved IEEE Standards Draft, subject to change.
  17483.  
  17484.  
  17485.  
  17486.  
  17487.  
  17488.  3.6 Word Expansions                                                   235
  17489.  
  17490.  
  17491.  
  17492.  
  17493.  
  17494.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17495.  
  17496.        PATH=$(printf %s:  rms/bin  bfox/bin ...)                            2
  17497.        PATH=$(printf %s  ~karels/bi~n :  bostic/bin)                          2
  17498.        for Dir in  maart~/bin  srb/bin ~...                                   2
  17499.        do         ~          ~                                              2
  17500.                PATH=${PATH:+$PATH:}$Dir                                     2
  17501.        done                                                                 2
  17502.  
  17503.  (In the first command, any number of directory names are concatenated and  2
  17504.  separated with colons, but it may be undesirable to end the variable with  2
  17505.  a colon because this is an obsolescent means to include dot at the end of  2
  17506.  the PATH.  In the second, explicit colons are used for each directory.     2
  17507.  In all cases, the shell performs tilde expansion on each directory         2
  17508.  because all are separate words to the shell.)                              2
  17509.  
  17510.  The exception was included to avoid breaking numerous KornShell scripts    2
  17511.  and interactive users and despite the fact that variable assignments in    2
  17512.  scripts derived from other systems will have to use quoting in some cases  2
  17513.  to allow literal tildes in strings.  (This latter problem should be        2
  17514.  relatively rare because only tildes preceding known login names in         2
  17515.  unquoted strings are affected.)                                            2
  17516.  
  17517.  Note that expressions in operands such as                                  2
  17518.  
  17519.        make -k mumble LIBDIR= chet/lib                                      2
  17520.                              ~
  17521.  do not qualify as shell variable assignments and tilde expansion is not    2
  17522.  performed (unless the command does so itself, which make does not).        2
  17523.  
  17524.  In an earlier draft, tilde expansion occurred following any unquoted       2
  17525.  equals-sign or colon, but this was removed because of its complexity and   2
  17526.  to avoid breaking commands such as:                                        2
  17527.  
  17528.        rcp hostname: marc/.profile .                                        2
  17529.                     ~
  17530.  A suggestion was made that the special sequence ``$ '' should be allowed   2
  17531.  to force tilde expansion anywhere.  Since this is n~ot historical           2
  17532.  practice, it has been left for future implementations to evaluate.  (The   2
  17533.  description in 3.2 requires that a dollar-sign be quoted to represent      2
  17534.  itself, so the $  combination is already unspecified.)                     2
  17535.                  ~
  17536.  The results of giving tilde with an unknown login name are undefined
  17537.  because the KornShell  + and  - constructs make use of this condition,
  17538.  but in general it is a~n error~to give an incorrect login name with tilde.
  17539.  The results of having HOME unset are unspecified because some historical
  17540.  shells treat this as an error.
  17541.  
  17542.  END_RATIONALE
  17543.  
  17544.  
  17545.  
  17546.  
  17547.                Copyright c 1991 IEEE.  All rights reserved.
  17548.       This is an unapproved IEEE Standards Draft, subject to change.
  17549.  
  17550.  
  17551.  
  17552.  
  17553.  
  17554.  236                                              3 Shell Command Language
  17555.  
  17556.  
  17557.  
  17558.  
  17559.  
  17560.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17561.  
  17562.  3.6.2  Parameter Expansion
  17563.  
  17564.  The format for parameter expansion is as follows:
  17565.  
  17566.        ${_e_x_p_r_e_s_s_i_o_n}
  17567.  
  17568.  where _e_x_p_r_e_s_s_i_o_n consists of all characters until the matching }.  Any }   2
  17569.  escaped by a backslash or within a quoted string, and characters in        2
  17570.  embedded arithmetic expansions, command substitutions, and variable        2
  17571.  expansions, shall not be examined in determining the matching }.
  17572.  
  17573.  The simplest form for parameter expansion is:
  17574.  
  17575.        ${_p_a_r_a_m_e_t_e_r}
  17576.  
  17577.  The value, if any, of _p_a_r_a_m_e_t_e_r shall be substituted.
  17578.  
  17579.  The parameter name or symbol can be enclosed in braces, which are
  17580.  optional except for positional parameters with more than one digit or
  17581.  when _p_a_r_a_m_e_t_e_r is followed by a character that could be interpreted as
  17582.  part of the name.  The matching closing brace shall be determined by
  17583.  counting brace levels, skipping over enclosed quoted strings and command
  17584.  substitutions.
  17585.  
  17586.  If the parameter name or symbol is not enclosed in braces, the expansion
  17587.  shall use the longest valid name (see 3.1.5), whether or not the symbol
  17588.  represented by that name exists.  If a parameter expansion occurs inside
  17589.  double-quotes:
  17590.  
  17591.      - Pathname expansion shall not be performed on the results of the
  17592.        expansion.
  17593.  
  17594.      - Field splitting shall not be performed on the results of the
  17595.        expansion, with the exception of @; see 3.5.2.
  17596.  
  17597.  In addition, a parameter expansion can be modified by using one of the
  17598.  following formats.  In each case that a value of _w_o_r_d is needed (based on
  17599.  the state of _p_a_r_a_m_e_t_e_r, as described below), _w_o_r_d shall be subjected to
  17600.  tilde expansion, parameter expansion, command substitution, and
  17601.  arithmetic expansion.  If _w_o_r_d is not needed, it shall not be expanded.
  17602.  The } character that delimits the following parameter expansion            1
  17603.  modifications shall be determined as described previously in this          1
  17604.  subclause and in 3.2.3.  (For example, ${foo-bar}xyz} would result in the  1
  17605.  expansion of foo followed by the string xyz} if foo is set, else the
  17606.  string barxyz}).
  17607.  
  17608.  
  17609.  
  17610.  
  17611.  
  17612.  
  17613.                Copyright c 1991 IEEE.  All rights reserved.
  17614.       This is an unapproved IEEE Standards Draft, subject to change.
  17615.  
  17616.  
  17617.  
  17618.  
  17619.  
  17620.  3.6 Word Expansions                                                   237
  17621.  
  17622.  
  17623.  
  17624.  
  17625.  
  17626.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17627.  
  17628.     ${_p_a_r_a_m_e_t_e_r:-_w_o_r_d}       Use Default Values.  If _p_a_r_a_m_e_t_e_r is unset or
  17629.                              null, the expansion of _w_o_r_d shall be
  17630.                              substituted; otherwise, the value of
  17631.                              _p_a_r_a_m_e_t_e_r shall be substituted.
  17632.  
  17633.     ${_p_a_r_a_m_e_t_e_r:=_w_o_r_d}       Assign Default Values.  If _p_a_r_a_m_e_t_e_r is unset
  17634.                              or null, the expansion of _w_o_r_d shall be
  17635.                              assigned to _p_a_r_a_m_e_t_e_r.  In all cases, the
  17636.                              final value of _p_a_r_a_m_e_t_e_r shall be
  17637.                              substituted.  Only variables, not positional
  17638.                              parameters or special parameters, can be
  17639.                              assigned in this way.
  17640.  
  17641.     ${_p_a_r_a_m_e_t_e_r:?[_w_o_r_d]}     Indicate Error if Null or Unset.  If
  17642.                              _p_a_r_a_m_e_t_e_r is unset or null, the expansion of
  17643.                              _w_o_r_d (or a message indicating it is unset if
  17644.                              _w_o_r_d is omitted) shall be written to standard
  17645.                              error and the shell shall exit with a nonzero
  17646.                              exit status.  Otherwise, the value of
  17647.                              _p_a_r_a_m_e_t_e_r shall be substituted.  An
  17648.                              interactive shell need not exit.
  17649.  
  17650.     ${_p_a_r_a_m_e_t_e_r:+_w_o_r_d}       Use Alternate Value.  If _p_a_r_a_m_e_t_e_r is unset
  17651.                              or null, null shall be substituted;
  17652.                              otherwise, the expansion of _w_o_r_d shall be
  17653.                              substituted.
  17654.  
  17655.  In the parameter expansions shown previously, use of the colon in the
  17656.  format results in a test for a parameter that is unset or null; omission
  17657.  of the colon results in a test for a parameter that is only unset.
  17658.  
  17659.     ${#_p_a_r_a_m_e_t_e_r}            String Length.  The length in characters of
  17660.                              the value of _p_a_r_a_m_e_t_e_r. If _p_a_r_a_m_e_t_e_r is * or
  17661.                              @, the result of the expansion is
  17662.                              unspecified.
  17663.  
  17664.  The following four varieties of parameter expansion provide for substring
  17665.  processing.  In each case, pattern matching notation (see 3.13), rather
  17666.  than regular expression notation, shall be used to evaluate the patterns.
  17667.  If _p_a_r_a_m_e_t_e_r is * or @, the result of the expansion is unspecified.
  17668.  Enclosing the full parameter expansion string in double-quotes shall not   1
  17669.  cause the following four varieties of pattern characters to be quoted,     1
  17670.  whereas quoting characters within the braces shall have this effect.
  17671.  
  17672.     ${_p_a_r_a_m_e_t_e_r%_w_o_r_d}        Remove Smallest Suffix Pattern.  The _w_o_r_d
  17673.                              shall be expanded to produce a pattern.  The
  17674.                              parameter expansion then shall result in
  17675.                              _p_a_r_a_m_e_t_e_r, with the smallest portion of the
  17676.                              suffix matched by the _p_a_t_t_e_r_n deleted.
  17677.  
  17678.  
  17679.                Copyright c 1991 IEEE.  All rights reserved.
  17680.       This is an unapproved IEEE Standards Draft, subject to change.
  17681.  
  17682.  
  17683.  
  17684.  
  17685.  
  17686.  238                                              3 Shell Command Language
  17687.  
  17688.  
  17689.  
  17690.  
  17691.  
  17692.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17693.  
  17694.     ${_p_a_r_a_m_e_t_e_r%%_w_o_r_d}       Remove Largest Suffix Pattern.  The _w_o_r_d
  17695.                              shall be expanded to produce a pattern.  The
  17696.                              parameter expansion then shall result in
  17697.                              _p_a_r_a_m_e_t_e_r, with the largest portion of the
  17698.                              suffix matched by the _p_a_t_t_e_r_n deleted.
  17699.  
  17700.     ${_p_a_r_a_m_e_t_e_r#_w_o_r_d}        Remove Smallest Prefix Pattern.  The _w_o_r_d
  17701.                              shall be expanded to produce a pattern.  The
  17702.                              parameter expansion then shall result in
  17703.                              _p_a_r_a_m_e_t_e_r, with the smallest portion of the
  17704.                              prefix matched by the _p_a_t_t_e_r_n deleted.
  17705.  
  17706.     ${_p_a_r_a_m_e_t_e_r##_w_o_r_d}       Remove Largest Prefix Pattern.  The _w_o_r_d
  17707.                              shall be expanded to produce a pattern.  The
  17708.                              parameter expansion then shall result in
  17709.                              _p_a_r_a_m_e_t_e_r, with the largest portion of the
  17710.                              prefix matched by the _p_a_t_t_e_r_n deleted.
  17711.  
  17712.  BEGIN_RATIONALE
  17713.  
  17714.  
  17715.  3.6.2.1  Parameter Expansion Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  17716.           _P_1_0_0_3._2)
  17717.  
  17718.  When the shell is scanning its input to determine the boundaries of a
  17719.  name, it is not bound by its knowledge of what names are already defined.
  17720.  For example, if F is a defined shell variable, the command "echo $Fred"
  17721.  does not echo the value of $F followed by red; it selects the longest
  17722.  possible valid name, Fred, which in this case might be unset.
  17723.  
  17724.  The rule for finding the closing } in ${...} is the one used in the
  17725.  KornShell and is upward compatible with the Bourne shell, which does not
  17726.  determine the closing } until the word is expanded.  The advantage of
  17727.  this is that incomplete expansions, such as
  17728.  
  17729.        ${foo
  17730.  
  17731.  can be determined during tokenization, rather than during expansion.
  17732.  
  17733.  The four expansions with the optional colon have been hard to understand
  17734.  from the historical documentation.  The following table summarizes the
  17735.  effect of the colon:
  17736.  
  17737.  
  17738.  
  17739.  
  17740.  
  17741.  
  17742.  
  17743.  
  17744.  
  17745.                Copyright c 1991 IEEE.  All rights reserved.
  17746.       This is an unapproved IEEE Standards Draft, subject to change.
  17747.  
  17748.  
  17749.  
  17750.  
  17751.  
  17752.  3.6 Word Expansions                                                   239
  17753.  
  17754.  
  17755.  
  17756.  
  17757.  
  17758.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17759.  
  17760.                              _pppp_aaaa_rrrr_aaaa_mmmm_eeee_tttt_eeee_rrrr        _pppp_aaaa_rrrr_aaaa_mmmm_eeee_tttt_eeee_rrrr     _pppp_aaaa_rrrr_aaaa_mmmm_eeee_tttt_eeee_rrrr
  17761.                           set and not null   set but null     unset
  17762.                           ________________   ____________   __________
  17763.      ${_p_a_r_a_m_e_t_e_r:-_w_o_r_d}      substitute       substitute    substitute
  17764.                              _p_a_r_a_m_e_t_e_r           _w_o_r_d          _w_o_r_d
  17765.  
  17766.      ${_p_a_r_a_m_e_t_e_r-_w_o_r_d}       substitute       substitute    substitute
  17767.                              _p_a_r_a_m_e_t_e_r           null          _w_o_r_d
  17768.  
  17769.      ${_p_a_r_a_m_e_t_e_r:=_w_o_r_d}      substitute         assign        assign
  17770.                              _p_a_r_a_m_e_t_e_r           _w_o_r_d          _w_o_r_d
  17771.  
  17772.      ${_p_a_r_a_m_e_t_e_r=_w_o_r_d}       substitute       substitute      assign
  17773.                              _p_a_r_a_m_e_t_e_r        _p_a_r_a_m_e_t_e_r        _w_o_r_d
  17774.  
  17775.      ${_p_a_r_a_m_e_t_e_r:?_w_o_r_d}      substitute         error,        error,
  17776.                              _p_a_r_a_m_e_t_e_r           exit          exit
  17777.  
  17778.      ${_p_a_r_a_m_e_t_e_r?_w_o_r_d}       substitute       substitute      error,
  17779.                              _p_a_r_a_m_e_t_e_r           null          exit
  17780.  
  17781.      ${_p_a_r_a_m_e_t_e_r:+_w_o_r_d}      substitute       substitute    substitute
  17782.                                 _w_o_r_d             null          null         1
  17783.  
  17784.      ${_p_a_r_a_m_e_t_e_r+_w_o_r_d}       substitute       substitute    substitute
  17785.                                 _w_o_r_d             _w_o_r_d          null         1
  17786.  
  17787.  
  17788.  In all cases shown with ``substitute,'' the expression is replaced with
  17789.  the value shown.  In all cases shown with ``assign,'' _p_a_r_a_m_e_t_e_r is
  17790.  assigned that value, which also replaces the expression.
  17791.  
  17792.  The string length and substring capabilities were included because of the
  17793.  demonstrated need for them, based on their usage in other shells, such as
  17794.  C-shell and KornShell.
  17795.  
  17796.  Historical versions of the KornShell have not performed tilde expansion
  17797.  on the word part of parameter expansion; however, it is more consistent
  17798.  to do so.
  17799.  
  17800.  
  17801.  
  17802.  
  17803.  
  17804.  
  17805.  
  17806.  
  17807.  
  17808.  
  17809.  
  17810.  
  17811.                Copyright c 1991 IEEE.  All rights reserved.
  17812.       This is an unapproved IEEE Standards Draft, subject to change.
  17813.  
  17814.  
  17815.  
  17816.  
  17817.  
  17818.  240                                              3 Shell Command Language
  17819.  
  17820.  
  17821.  
  17822.  
  17823.  
  17824.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17825.  
  17826.  _E_x_a_m_p_l_e_s
  17827.  
  17828.     ${_p_a_r_a_m_e_t_e_r:-_w_o_r_d}
  17829.  
  17830.                 In this example, ls is executed only if x is null or
  17831.                 unset.  [The $(ls) command substitution notation is
  17832.                 explained in 3.6.3.]
  17833.  
  17834.                 ${x:-$(ls)}
  17835.  
  17836.     ${_p_a_r_a_m_e_t_e_r:=_w_o_r_d}
  17837.  
  17838.                 unset X
  17839.                 echo ${X:=abc}
  17840.                 abc
  17841.  
  17842.     ${_p_a_r_a_m_e_t_e_r:?_w_o_r_d}
  17843.  
  17844.                 unset posix
  17845.                 echo ${posix:?}
  17846.                 sh: posix: parameter null or not set
  17847.  
  17848.     ${_p_a_r_a_m_e_t_e_r:+_w_o_r_d}
  17849.  
  17850.                 set a b c
  17851.                 echo ${3:+posix}
  17852.                 posix
  17853.  
  17854.     ${#_p_a_r_a_m_e_t_e_r}
  17855.  
  17856.                 HOME=/usr/posix
  17857.                 echo ${#HOME}
  17858.                 10
  17859.  
  17860.     ${_p_a_r_a_m_e_t_e_r%_w_o_r_d}
  17861.  
  17862.                 x=file.c
  17863.                 echo ${x%.c}.o
  17864.                 file.o
  17865.  
  17866.     ${_p_a_r_a_m_e_t_e_r%%_w_o_r_d}
  17867.  
  17868.                 x=posix/src/std
  17869.                 echo ${x%%/*}
  17870.                 posix
  17871.  
  17872.  
  17873.  
  17874.  
  17875.  
  17876.  
  17877.                Copyright c 1991 IEEE.  All rights reserved.
  17878.       This is an unapproved IEEE Standards Draft, subject to change.
  17879.  
  17880.  
  17881.  
  17882.  
  17883.  
  17884.  3.6 Word Expansions                                                   241
  17885.  
  17886.  
  17887.  
  17888.  
  17889.  
  17890.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  17891.  
  17892.     ${_p_a_r_a_m_e_t_e_r#_w_o_r_d}
  17893.  
  17894.                 x=$HOME/src/cmd
  17895.                 echo ${x#$HOME}
  17896.                 /src/cmd
  17897.  
  17898.     ${_p_a_r_a_m_e_t_e_r##_w_o_r_d}
  17899.  
  17900.                 x=/one/two/three
  17901.                 echo ${x##*/}
  17902.                 three
  17903.  
  17904.  The double-quoting of patterns is different depending on where the
  17905.  double-quotes are placed:
  17906.  
  17907.     "${x#*}"         The asterisk is a pattern character.
  17908.  
  17909.     ${x#"*"}         The literal asterisk is quoted and not special.
  17910.  
  17911.  END_RATIONALE
  17912.  
  17913.  
  17914.  3.6.3  Command Substitution
  17915.  
  17916.  Command substitution allows the output of a command to be substituted in
  17917.  place of the command name itself.  Command substitution shall occur when
  17918.  the command is enclosed as follows:
  17919.  
  17920.        $(_c_o_m_m_a_n_d)
  17921.  
  17922.  or (``backquoted'' version):
  17923.  
  17924.        `_c_o_m_m_a_n_d`
  17925.  
  17926.  The shell shall expand the command substitution by executing _c_o_m_m_a_n_d in a
  17927.  subshell environment (see 3.12) and replacing the command substitution
  17928.  [the text of _c_o_m_m_a_n_d plus the enclosing $( ) or backquotes] with the
  17929.  standard output of the command, removing sequences of one or more
  17930.  <newline>s at the end of the substitution.  (Embedded <newline>s before
  17931.  the end of the output shall not be removed; however, during field
  17932.  splitting, they may be translated into <space>s, depending on the value
  17933.  of IFS and quoting that is in effect.)
  17934.  
  17935.  Within the backquoted style of command substitution, backslash shall
  17936.  retain its literal meaning, except when followed by
  17937.  
  17938.        $  `  \
  17939.  
  17940.  (dollar-sign, backquote, backslash).  The search for the matching          2
  17941.  
  17942.  
  17943.                Copyright c 1991 IEEE.  All rights reserved.
  17944.       This is an unapproved IEEE Standards Draft, subject to change.
  17945.  
  17946.  
  17947.  
  17948.  
  17949.  
  17950.  242                                              3 Shell Command Language
  17951.  
  17952.  
  17953.  
  17954.  
  17955.  
  17956.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  17957.  
  17958.  backquote shall be satisfied by the first backquote found without a        2
  17959.  preceding backslash; during this search, if a nonescaped backquote is      2
  17960.  encountered within a shell comment, a here-document, an embedded command   2
  17961.  substitution of the $(_c_o_m_m_a_n_d) form, or a quoted string, undefined         2
  17962.  results occur.  A single- or double-quoted string that begins, but does
  17963.  not end, within the `...` sequence produces undefined results.
  17964.  
  17965.  With the $(_c_o_m_m_a_n_d) form, all characters following the open parenthesis
  17966.  to the matching closing parenthesis constitute the _c_o_m_m_a_n_d. Any valid      2
  17967.  shell script can be used for _c_o_m_m_a_n_d, except:                              2
  17968.  
  17969.      - A script consisting solely of redirections produces unspecified      2
  17970.        results.                                                             2
  17971.  
  17972.      - See the restriction on single subshells described below.             2
  17973.  
  17974.  The results of command substitution shall not be processed for further     1
  17975.  tilde expansion, parameter expansion, command substitution, or arithmetic  1
  17976.  expansion.  If a command substitution occurs inside double-quotes, field
  17977.  splitting and pathname expansion shall not be performed on the results of
  17978.  the substitution.
  17979.  
  17980.  Command substitution can be nested.  To specify nesting within the
  17981.  backquoted version, the application shall precede the inner backquotes
  17982.  with backslashes; for example,
  17983.  
  17984.        \`_c_o_m_m_a_n_d\`
  17985.  
  17986.  If the command substitution consists of a single subshell, such as
  17987.  
  17988.        $( (_c_o_m_m_a_n_d) )
  17989.  
  17990.  a conforming application shall separate the $( and ( into two tokens
  17991.  (i.e., separate them with white space).
  17992.  
  17993.  BEGIN_RATIONALE
  17994.  
  17995.  
  17996.  3.6.3.1  Command Substitution Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  17997.           _P_1_0_0_3._2)
  17998.  
  17999.  The new $( ) form of command substitution was adopted from the KornShell
  18000.  to solve a problem of inconsistent behavior when using backquotes.  For
  18001.  example:
  18002.  
  18003.                         _____C_o_m_m_a_n_d_______   O_u_t_p_u_t_
  18004.                         echo '\$x'           \$x
  18005.  
  18006.  
  18007.  
  18008.  
  18009.                Copyright c 1991 IEEE.  All rights reserved.
  18010.       This is an unapproved IEEE Standards Draft, subject to change.
  18011.  
  18012.  
  18013.  
  18014.  
  18015.  
  18016.  3.6 Word Expansions                                                   243
  18017.  
  18018.  
  18019.  
  18020.  
  18021.  
  18022.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18023.  
  18024.                         echo `echo '\$x'`    $x
  18025.                         echo $(echo '\$x')   \$x
  18026.  
  18027.  Additionally, the backquoted syntax has historical restrictions on the     2
  18028.  contents of the embedded command.  While the new $( ) form can process     2
  18029.  any kind of valid embedded script, the backquoted cannot handle some       2
  18030.  valid scripts that include backquotes.  For example, these otherwise       2
  18031.  valid embedded scripts do not work in the left column, but do work on the  2
  18032.  right:                                                                     2
  18033.  
  18034.          echo `                        echo $(                              2
  18035.          cat <<\eof                    cat <<\eof                           2
  18036.          a here-doc with `             a here-doc with )                    2
  18037.          eof                           eof                                  2
  18038.          `                             )                                    2
  18039.  
  18040.          echo `                        echo $(                              2
  18041.          echo abc # a comment with `   echo abc # a comment with )          2
  18042.          `                             )                                    2
  18043.  
  18044.          echo `                        echo $(                              2
  18045.          echo '`'                      echo ')'                             2
  18046.          `                             )                                    2
  18047.  
  18048.  Some historical KornShell implementations did not process the first two    2
  18049.  examples correctly, but the author has agreed to make the appropriate      2
  18050.  modifications to do so.  The KornShell will also be modified so that the   2
  18051.  following works:                                                           2
  18052.  
  18053.        echo $(                                                              2
  18054.                case word in                                                 2
  18055.                        [Ff]oo) echo found foo ;;                            2
  18056.                esac                                                         2
  18057.        )                                                                    2
  18058.  
  18059.  Because of these inconsistent behaviors, the backquoted variety of
  18060.  command substitution is not recommended for new applications that nest
  18061.  command substitutions or attempt to embed complex scripts.  Because of     2
  18062.  its widespread historical use, particularly by interactive users,
  18063.  however, the backquotes were retained in POSIX.2 without being declared
  18064.  obsolescent.
  18065.  
  18066.  The KornShell feature:
  18067.  
  18068.        If _c_o_m_m_a_n_d is of the form <_w_o_r_d, _w_o_r_d is expanded to generate a
  18069.        pathname, and the value of the command substitution is the contents
  18070.        of this file with any trailing <newline>_s deleted.
  18071.  
  18072.  
  18073.  
  18074.  
  18075.                Copyright c 1991 IEEE.  All rights reserved.
  18076.       This is an unapproved IEEE Standards Draft, subject to change.
  18077.  
  18078.  
  18079.  
  18080.  
  18081.  
  18082.  244                                              3 Shell Command Language
  18083.  
  18084.  
  18085.  
  18086.  
  18087.  
  18088.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18089.  
  18090.  was omitted from this standard because $(cat word) is an appropriate
  18091.  substitute.  However, to prevent breaking numerous scripts relying on      2
  18092.  this feature, it is unspecified to have a script within $( ) that has      2
  18093.  only redirections.                                                         2
  18094.  
  18095.  The requirement to separate $( and ( when a single subshell is command-
  18096.  substituted is to avoid any ambiguities with Arithmetic Expansion.  See
  18097.  3.6.4.1.
  18098.  
  18099.  END_RATIONALE
  18100.  
  18101.  
  18102.  3.6.4  Arithmetic Expansion
  18103.  
  18104.  Arithmetic expansion provides a mechanism for evaluating an arithmetic
  18105.  expression and substituting its value.  The format for arithmetic
  18106.  expansion shall be as follows:
  18107.  
  18108.        $((_e_x_p_r_e_s_s_i_o_n))
  18109.  
  18110.  The expression shall be treated as if it were in double-quotes, except
  18111.  that a double-quote inside the expression is not treated specially.  The
  18112.  shell shall expand all tokens in the expression for parameter expansion,
  18113.  command substitution, and quote removal.
  18114.  
  18115.  Next, the shell shall treat this as an arithmetic expression and
  18116.  substitute the value of the expression.  The arithmetic expression shall
  18117.  be processed according to the rules given in 2.9.2.1, with the following
  18118.  exceptions:
  18119.  
  18120.      (1)  Only integer arithmetic is required.
  18121.  
  18122.      (2)  The sizeof() operator and the prefix and postfix ++ and --
  18123.           operators are not required.
  18124.  
  18125.      (3)  Selection, Iteration, and Jump Statements are not supported.
  18126.  
  18127.  As an extension, the shell may recognize arithmetic expressions beyond
  18128.  those listed.  If the expression is invalid, the expansion fails and the
  18129.  shell shall write a message to standard error indicating the failure.
  18130.  
  18131.  BEGIN_RATIONALE
  18132.  
  18133.  
  18134.  
  18135.  
  18136.  
  18137.  
  18138.  
  18139.  
  18140.  
  18141.                Copyright c 1991 IEEE.  All rights reserved.
  18142.       This is an unapproved IEEE Standards Draft, subject to change.
  18143.  
  18144.  
  18145.  
  18146.  
  18147.  
  18148.  3.6 Word Expansions                                                   245
  18149.  
  18150.  
  18151.  
  18152.  
  18153.  
  18154.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18155.  
  18156.  3.6.4.1  Arithmetic Expansion Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  18157.           _P_1_0_0_3._2)
  18158.  
  18159.  Numerous ballots were received objecting to the inclusion of the (( ))
  18160.  form of KornShell arithmetic in previous drafts.  The developers of the
  18161.  standard concluded that there is a strong desire for some kind of
  18162.  arithmetic evaluator to replace expr, and that tying it in with $ makes
  18163.  it fit in nicely with the standard shell language, and provides access to
  18164.  arithmetic evaluation in places where accessing a utility would be
  18165.  inconvenient or clumsy.
  18166.  
  18167.  Following long debate by interested members of the balloting group, the
  18168.  syntax and semantics for arithmetic were changed.  The language is
  18169.  essentially a pure arithmetic evaluator of constants and operators
  18170.  (excluding assignment) and represents a simple subset of the previous
  18171.  arithmetic language [which was derived from the KornShell's (( ))
  18172.  construct].  The syntax was changed from that of a command denoted by
  18173.  ((_e_x_p_r_e_s_s_i_o_n)), to an expansion denoted by $((_e_x_p_r_e_s_s_i_o_n)).  The new form
  18174.  is a dollar expansion ($), which evaluates the expression and substitutes
  18175.  the resulting value.  Objections to the previous style of arithmetic
  18176.  included that it was too complicated, did not fit in well with the
  18177.  shell's use of variables, and the syntax conflicted with subshells.  The
  18178.  justification for the new syntax is that the shell is traditionally a
  18179.  macro language, and if a new feature is to be added, it should be done by
  18180.  extending the capabilities presented by the current model of the shell,
  18181.  rather than by inventing a new one outside the model:  adding a new
  18182.  dollar expansion was perceived to be the most intuitive and least
  18183.  destructive way to add such a new capability.
  18184.  
  18185.  In Drafts 9 and 10, a form $[_e_x_p_r_e_s_s_i_o_n] was used.  It was functionally
  18186.  equivalent to the $(( )) of the current text, but objections were lodged
  18187.  that the 1988 KornShell had already implemented $(( )) and there was no
  18188.  compelling reason to invent yet another syntax.  Furthermore, the $[]
  18189.  syntax had a minor incompatibility involving the patterns in case
  18190.  statements.
  18191.  
  18192.  The portion of the C Standard {7} arithmetic operations selected
  18193.  corresponds to the operations historically supported in the KornShell.
  18194.  
  18195.  A simple example using arithmetic expansion:
  18196.  
  18197.        # repeat a command 100 times
  18198.        x=100
  18199.        while [ $x -gt 0 ]
  18200.        do
  18201.                _c_o_m_m_a_n_d
  18202.                x=$(($x-1))
  18203.        done
  18204.  
  18205.  
  18206.  
  18207.                Copyright c 1991 IEEE.  All rights reserved.
  18208.       This is an unapproved IEEE Standards Draft, subject to change.
  18209.  
  18210.  
  18211.  
  18212.  
  18213.  
  18214.  246                                              3 Shell Command Language
  18215.  
  18216.  
  18217.  
  18218.  
  18219.  
  18220.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18221.  
  18222.  It was concluded that the test command ([) was sufficient for the
  18223.  majority of relational arithmetic tests, and that tests involving
  18224.  complicated relational expressions within the shell are rare, yet could
  18225.  still be accommodated by testing the value of $(()) itself.  For example:
  18226.  
  18227.        # a complicated relational expression
  18228.        while [ $(( (($x + $y)/($a * $b)) < ($foo*$bar) )) -ne 0 ]
  18229.  
  18230.  or better yet, the rare script that has many complex relational
  18231.  expressions could define a function like this:
  18232.  
  18233.        val() {
  18234.                return $((!$1))
  18235.        }
  18236.  
  18237.  and complicated tests would be less intimidating:
  18238.  
  18239.        while val $(( (($x + $y)/($a * $b)) < ($foo*$bar) ))
  18240.        do
  18241.                # some calculations
  18242.        done
  18243.  
  18244.  Another suggestion was to modify true and false to take an optional
  18245.  argument, and true would exit true only if the argument is nonzero, and
  18246.  false would exit false only if the argument is nonzero.  The suggestion
  18247.  was not favorably received by the balloting group (those contacted were
  18248.  negative about it, all others were silent in their latest ballots).
  18249.  
  18250.        while true $(($x > 5 && $y <= 25))
  18251.  
  18252.  There is a minor portability concern with the new syntax.  The example
  18253.  $((2+2)) could have been intended to mean a command substitution of a
  18254.  utility named 2+2 in a subshell.  The developers of POSIX.2 consider this
  18255.  to be obscure and isolated to some KornShell scripts [because $( )
  18256.  command substitution existed previously only in the KornShell].  The text
  18257.  on Command Substitution has been changed to require that the $( and ( be
  18258.  separate tokens if this usage is needed.
  18259.  
  18260.  An example such as
  18261.  
  18262.        echo $((echo hi);(echo there))
  18263.  
  18264.  should not be misinterpreted by the shell as arithmetic because attempts
  18265.  to balance the parentheses pairs would indicate that they are subshells.   1
  18266.  However, as indicated by 3.1.1, a conforming application must separate     1
  18267.  two adjacent parentheses with white space to indicate nested subshells.    1
  18268.  
  18269.  END_RATIONALE                                                              1
  18270.  
  18271.  
  18272.  
  18273.                Copyright c 1991 IEEE.  All rights reserved.
  18274.       This is an unapproved IEEE Standards Draft, subject to change.
  18275.  
  18276.  
  18277.  
  18278.  
  18279.  
  18280.  3.6 Word Expansions                                                   247
  18281.  
  18282.  
  18283.  
  18284.  
  18285.  
  18286.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18287.  
  18288.  3.6.5  Field Splitting
  18289.  
  18290.  After parameter expansion (3.6.2), command substitution (3.6.3), and
  18291.  arithmetic expansion (3.6.4) the shell shall scan the results of
  18292.  expansions and substitutions that did not occur in double-quotes for
  18293.  field splitting and multiple fields can result.
  18294.  
  18295.  The shell shall treat each character of the IFS as a delimiter and use
  18296.  the delimiters to split the results of parameter expansion and command
  18297.  substitution into fields.
  18298.  
  18299.      (1)  If the value of IFS is <space>, <tab>, and <newline>, or if it
  18300.           is unset, any sequence of <space>, <tab>, or <newline>
  18301.           characters at the beginning or end of the input shall be ignored
  18302.           and any sequence of those characters within the input shall
  18303.           delimit a field.  (For example, the input
  18304.  
  18305.                 <newline><space><tab>foo<tab><tab>bar<space>
  18306.  
  18307.           yields two fields, foo and bar).
  18308.  
  18309.      (2)  If the value of IFS is null, no field splitting shall be
  18310.           performed.
  18311.  
  18312.      (3)  Otherwise, the following rules shall be applied in sequence.      1
  18313.           The term ``IFS white space'' is used to mean any sequence (zero   1
  18314.           or more instances) of white-space characters that are in the IFS  1
  18315.           value (e.g., if IFS contains <space><comma><tab>, any sequence    1
  18316.           of <space> and <tab> characters is considered IFS white space).   1
  18317.  
  18318.            (a)  IFS white space shall be ignored at the beginning and end   1
  18319.                 of the input.                                               1
  18320.  
  18321.            (b)  Each occurrence in the input of an IFS character that is    1
  18322.                 not IFS white space, along with any adjacent IFS white      1
  18323.                 space, shall delimit a field, as described previously.      1
  18324.  
  18325.            (c)  Nonzero-length IFS white space shall delimit a field.       1
  18326.  
  18327.  BEGIN_RATIONALE
  18328.  
  18329.  
  18330.  3.6.5.1  Field Splitting Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  18331.           _P_1_0_0_3._2)
  18332.  
  18333.  The operation of field splitting using IFS as described in earlier drafts
  18334.  was based on the way the KornShell splits words, but is incompatible with
  18335.  other common versions of the shell.  However, each has merit, and so a
  18336.  decision was made to allow both.  If the IFS variable is unset, or is
  18337.  <space><tab><newline>, the operation is equivalent to the way the
  18338.  
  18339.                Copyright c 1991 IEEE.  All rights reserved.
  18340.       This is an unapproved IEEE Standards Draft, subject to change.
  18341.  
  18342.  
  18343.  
  18344.  
  18345.  
  18346.  248                                              3 Shell Command Language
  18347.  
  18348.  
  18349.  
  18350.  
  18351.  
  18352.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18353.  
  18354.  System V shell splits words.  Using characters outside the
  18355.  <space><tab><newline> set yields the KornShell behavior, where each of
  18356.  the non-<space><tab><newline> characters is significant.  This behavior,
  18357.  which affords the most flexibility, was taken from the way the original
  18358.  awk handled field splitting.
  18359.  
  18360.  The (3) rule can be summarized as a pseudo ERE:                            1
  18361.  
  18362.        (s*ns*|s+)                                                           1
  18363.  
  18364.  where s is an IFS white-space character and n is a character in the IFS    1
  18365.  that is not white space.  Any string matching that ERE delimits a field,   1
  18366.  except that the s+ form does not delimit fields at the beginning or the    1
  18367.  end of a line.  For example, if IFS is <space><comma>, the string          1
  18368.  
  18369.        <space><space>red<space><space>,<space>white<space>blue              1
  18370.  
  18371.  yields the three colors as the delimited fields.                           1
  18372.  
  18373.  END_RATIONALE                                                              1
  18374.  
  18375.  
  18376.  3.6.6  Pathname Expansion
  18377.  
  18378.  After field splitting, if set -f is not in effect, each field in the
  18379.  resulting command line shall be expanded using the algorithm described in
  18380.  3.13, qualified by the rules in 3.13.3.
  18381.  
  18382.  
  18383.  3.6.7  Quote Removal
  18384.  
  18385.  The quote characters
  18386.  
  18387.        \  '  "
  18388.  
  18389.  (backslash, single-quote, double-quote) that were present in the original
  18390.  word shall be removed unless they have themselves been quoted.
  18391.  
  18392.  
  18393.  
  18394.  3.7  Redirection
  18395.  
  18396.  Redirection is used to open and close files for the current shell
  18397.  execution environment (see 3.12) or for any command.  _R_e_d_i_r_e_c_t_i_o_n
  18398.  _o_p_e_r_a_t_o_r_s can be used with numbers representing file descriptors (see the
  18399.  definition in POSIX.1 {8}) as described below.  See also 2.9.1.  The
  18400.  relationship between these file descriptors and access to them in a
  18401.  programming language is specified in the language binding for that
  18402.  language to this standard.
  18403.  
  18404.  
  18405.                Copyright c 1991 IEEE.  All rights reserved.
  18406.       This is an unapproved IEEE Standards Draft, subject to change.
  18407.  
  18408.  
  18409.  
  18410.  
  18411.  
  18412.  3.7 Redirection                                                       249
  18413.  
  18414.  
  18415.  
  18416.  
  18417.  
  18418.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18419.  
  18420.  The overall format used for redirection is:
  18421.  
  18422.        [_n]_r_e_d_i_r-_o_p   _w_o_r_d
  18423.  
  18424.  The number _n is an optional decimal number designating the file
  18425.  descriptor number; it shall be delimited from any preceding text and
  18426.  immediately precede the redirection operator _r_e_d_i_r-_o_p. If _n is quoted,
  18427.  the number shall not be recognized as part of the redirection expression.
  18428.  (For example, echo \2>a writes the character 2 into file a).  If any part
  18429.  of _r_e_d_i_r-_o_p is quoted, no redirection expression shall be recognized.
  18430.  (For example, echo 2\>a writes the characters 2>a to standard output.)
  18431.  The optional number, redirection operator, and _w_o_r_d shall not appear in
  18432.  the arguments provided to the command to be executed (if any).
  18433.  
  18434.  In this standard, open files are represented by decimal numbers starting
  18435.  with zero.  It is implementation defined what the largest value can be;
  18436.  however, all implementations shall support at least 0 through 9 for use
  18437.  by the application.  These numbers are called _f_i_l_e _d_e_s_c_r_i_p_t_o_r_s.  The
  18438.  values 0, 1, and 2 have special meaning and conventional uses and are
  18439.  implied by certain redirection operations; they are referred to as
  18440.  _s_t_a_n_d_a_r_d _i_n_p_u_t, _s_t_a_n_d_a_r_d _o_u_t_p_u_t, and _s_t_a_n_d_a_r_d _e_r_r_o_r, respectively.
  18441.  Programs usually take their input from standard input, and write output
  18442.  on standard output.  Error messages are usually written to standard
  18443.  error.  The redirection operators can be preceded by one or more digits
  18444.  (with no intervening <blank>s allowed) to designate the file descriptor
  18445.  number.
  18446.  
  18447.  If the redirection operator is << or <<-, the word that follows the
  18448.  redirection operator shall be subjected to quote removal; it is
  18449.  unspecified whether any of the other expansions occur.  For the other
  18450.  redirection operators, the word that follows the redirection operator
  18451.  shall be subjected to tilde expansion, parameter expansion, command
  18452.  substitution, arithmetic expansion, and quote removal.  Pathname
  18453.  expansion shall not be performed on the word by a noninteractive shell;
  18454.  an interactive shell may perform it, but shall do so only when the
  18455.  expansion would result in one word.
  18456.  
  18457.  If more than one redirection operator is specified with a command, the
  18458.  order of evaluation is from beginning to end.
  18459.  
  18460.  In the following description of redirections, references are made to
  18461.  opening and creating files.  These references shall conform to the
  18462.  requirements in 2.9.1.4.  A failure to open or create a file shall cause
  18463.  the redirection to fail.
  18464.  
  18465.  
  18466.  
  18467.  
  18468.  
  18469.  
  18470.  
  18471.                Copyright c 1991 IEEE.  All rights reserved.
  18472.       This is an unapproved IEEE Standards Draft, subject to change.
  18473.  
  18474.  
  18475.  
  18476.  
  18477.  
  18478.  250                                              3 Shell Command Language
  18479.  
  18480.  
  18481.  
  18482.  
  18483.  
  18484.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18485.  
  18486.  3.7.1  Redirecting Input
  18487.  
  18488.  Input redirection shall cause the file whose name results from the
  18489.  expansion of _w_o_r_d to be opened for reading on the designated file
  18490.  descriptor, or standard input if the file descriptor is not specified.
  18491.  
  18492.  The general format for redirecting input is:
  18493.  
  18494.        [_n]<_w_o_r_d
  18495.  
  18496.  where the optional _n represents the file descriptor number.  If the
  18497.  number is omitted, the redirection shall refer to standard input (file
  18498.  descriptor 0).
  18499.  
  18500.  
  18501.  3.7.2  Redirecting Output
  18502.  
  18503.  The two general formats for redirecting output are:
  18504.  
  18505.        [_n]>_w_o_r_d
  18506.        [_n]>|_w_o_r_d
  18507.  
  18508.  where the optional _n represents the file descriptor number.  If the
  18509.  number is omitted, the redirection shall refer to standard output (file
  18510.  descriptor 1).
  18511.  
  18512.  Output redirection using the > format shall fail if the _n_o_c_l_o_b_b_e_r option   1
  18513.  is set (see the description of set -C in 3.14.11) and the file named by    1
  18514.  the expansion of _w_o_r_d exists and is a regular file.  Otherwise,            1
  18515.  redirection using the > or >| formats shall cause the file whose name      1
  18516.  results from the expansion of _w_o_r_d to be created and opened for ouput on
  18517.  the designated file descriptor, or standard output if none is specified.
  18518.  If the file does not exist, it shall be created; otherwise, it shall be
  18519.  truncated to be an empty file after being opened.
  18520.  
  18521.  
  18522.  3.7.3  Appending Redirected Output
  18523.  
  18524.  Appended output redirection shall cause the file whose name results from
  18525.  the expansion of word to be opened for output on the designated file
  18526.  descriptor.  The file is opened as if the POSIX.1 {8} _o_p_e_n() function was
  18527.  called with the O_APPEND flag.  If the file does not exist, it shall be
  18528.  created.
  18529.  
  18530.  The general format for appending redirected output is as follows:
  18531.  
  18532.        [_n]>>_w_o_r_d
  18533.  
  18534.  where the optional _n represents the file descriptor number.
  18535.  
  18536.  
  18537.                Copyright c 1991 IEEE.  All rights reserved.
  18538.       This is an unapproved IEEE Standards Draft, subject to change.
  18539.  
  18540.  
  18541.  
  18542.  
  18543.  
  18544.  3.7 Redirection                                                       251
  18545.  
  18546.  
  18547.  
  18548.  
  18549.  
  18550.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18551.  
  18552.  3.7.4  Here-Document
  18553.  
  18554.  The redirection operators << and <<- both allow redirection of lines
  18555.  contained in a shell input file, known as a _h_e_r_e-_d_o_c_u_m_e_n_t, to the
  18556.  standard input of a command.
  18557.  
  18558.  The here-document shall be treated as a single word that begins after the
  18559.  next <newline> and continues until there is a line containing only the
  18560.  delimiter, with no trailing <blank>_s.  Then the next here-document
  18561.  starts, if there is one.  The format is as follows:
  18562.  
  18563.        [_n]<<_w_o_r_d
  18564.                _h_e_r_e-_d_o_c_u_m_e_n_t
  18565.        _d_e_l_i_m_i_t_e_r
  18566.  
  18567.  If any character in _w_o_r_d is quoted, the delimiter shall be formed by
  18568.  performing quote removal on _w_o_r_d, and the here-document lines shall not
  18569.  be expanded.  Otherwise, the delimiter shall be the _w_o_r_d itself.
  18570.  
  18571.  If no characters in _w_o_r_d are quoted, all lines of the here-document shall
  18572.  be expanded for parameter expansion, command substitution, and arithmetic
  18573.  expansion.  In this case, the backslash in the input shall behave as the
  18574.  backslash inside double-quotes (see 3.2.3).  However, the double-quote
  18575.  character (") shall not be treated specially within a here-document,
  18576.  except when the double-quote appears within $( ), ` `, or ${ }.            1
  18577.  
  18578.  If the redirection symbol is <<-, all leading <tab> characters shall be
  18579.  stripped from input lines and the line containing the trailing delimiter.
  18580.  If more than one << or <<- operator is specified on a line, the here-
  18581.  document associated with the first operator shall be supplied first by
  18582.  the application and shall be read first by the shell.
  18583.  
  18584.  
  18585.  3.7.5  Duplicating an Input File Descriptor
  18586.  
  18587.  The redirection operator
  18588.  
  18589.        [_n]<&_w_o_r_d
  18590.  
  18591.  is used to duplicate one input file descriptor from another, or to close
  18592.  one.  If _w_o_r_d evaluates to one or more digits, the file descriptor
  18593.  denoted by _n, or standard input if _n is not specified, shall be made to
  18594.  be a copy of the file descriptor denoted by _w_o_r_d; if the digits in _w_o_r_d
  18595.  do not represent a file descriptor already open for input, a redirection   1
  18596.  error shall result (see 3.8.1).  If _w_o_r_d evaluates to -, file descriptor   1
  18597.  _n, or standard input if _n is not specified, shall be closed.  If _w_o_r_d
  18598.  evaluates to something else, the behavior is unspecified.
  18599.  
  18600.  
  18601.  
  18602.  
  18603.                Copyright c 1991 IEEE.  All rights reserved.
  18604.       This is an unapproved IEEE Standards Draft, subject to change.
  18605.  
  18606.  
  18607.  
  18608.  
  18609.  
  18610.  252                                              3 Shell Command Language
  18611.  
  18612.  
  18613.  
  18614.  
  18615.  
  18616.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18617.  
  18618.  3.7.6  Duplicating an Output File Descriptor
  18619.  
  18620.  The redirection operator
  18621.  
  18622.        [_n]>&_w_o_r_d
  18623.  
  18624.  is used to duplicate one output file descriptor from another, or to close
  18625.  one.  If _w_o_r_d evaluates to one or more digits, the file descriptor
  18626.  denoted by _n, or standard output if _n is not specified, shall be made to
  18627.  be a copy of the file descriptor denoted by _w_o_r_d; if the digits in _w_o_r_d
  18628.  do not represent a file descriptor already open for output, a redirection  1
  18629.  error shall result (see 3.8.1).  If _w_o_r_d evaluates to -, file descriptor   1
  18630.  _n, or standard output if _n is not specified, shall be closed.  If _w_o_r_d
  18631.  evaluates to something else, the behavior is unspecified.
  18632.  
  18633.  
  18634.  3.7.7  Open File Descriptors for Reading and Writing.
  18635.  
  18636.  The redirection operator
  18637.  
  18638.        [_n]<>_w_o_r_d
  18639.  
  18640.  shall cause the file whose name is the expansion of _w_o_r_d to be opened for
  18641.  both reading and writing on the file descriptor denoted by _n, or standard
  18642.  input if _n is not specified.  If the file does not exist, it shall be
  18643.  created.
  18644.  
  18645.  BEGIN_RATIONALE
  18646.  
  18647.  
  18648.  3.7.8  Redirection Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  18649.  
  18650.  In the C binding for POSIX.1 {8}, file descriptors are integers in the
  18651.  range 0 - ({OPEN_MAX}-1).  The file descriptors discussed in Redirection
  18652.  are that same set of small integers.
  18653.  
  18654.  As POSIX.2 is being finalized, it is not known how file descriptors will
  18655.  be represented in the language-independent description of POSIX.1 {8}.
  18656.  The current consensus appears to be that they will remain as small
  18657.  integers, but it is still possible that they will be defined as an opaque
  18658.  type.  If they remain as integers, then the current POSIX.2 wording is
  18659.  acceptable.  If they become an opaque type, then the C binding to
  18660.  POSIX.1 {8} will have to define the mapping from the binding's small
  18661.  integers to the opaque type, and the Redirection clause in POSIX.2 will
  18662.  have to be modified to specify that same mapping.
  18663.  
  18664.  Having multidigit file descriptor numbers for I/O redirection can cause
  18665.  some obscure compatibility problems.  Specifically, scripts that depend
  18666.  on an example command:
  18667.  
  18668.  
  18669.                Copyright c 1991 IEEE.  All rights reserved.
  18670.       This is an unapproved IEEE Standards Draft, subject to change.
  18671.  
  18672.  
  18673.  
  18674.  
  18675.  
  18676.  3.7 Redirection                                                       253
  18677.  
  18678.  
  18679.  
  18680.  
  18681.  
  18682.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18683.  
  18684.        echo 22>/dev/null
  18685.  
  18686.  echoing "2" are somewhat broken to begin with.  However, the file
  18687.  descriptor number still must be delimited from the preceding text.  For
  18688.  example,
  18689.  
  18690.        cat file2>foo
  18691.  
  18692.  will write the contents of file2, not the contents of file.
  18693.  
  18694.  The >| format of output redirection was adopted from the KornShell.
  18695.  Along with the _n_o_c_l_o_b_b_e_r option, set -C, it provides a safety feature to
  18696.  prevent inadvertent overwriting of existing files.  (See the rationale
  18697.  with the pathchk utility for why this step was taken.)  The restriction
  18698.  on regular files is historical practice.
  18699.  
  18700.  The System V shell and the KornShell have differed historically on
  18701.  pathname expansion of _w_o_r_d; the former never performed it, the latter
  18702.  only when the result was a single field (file).  As a compromise, it was
  18703.  decided that the KornShell functionality was useful, but only as a
  18704.  shorthand device for interactive users.  No reasonable shell script would
  18705.  be written with a command such as:
  18706.  
  18707.        cat foo > a*
  18708.  
  18709.  Thus, shell scripts are prohibited from doing it, while interactive users
  18710.  can select the shell with which they are most comfortable.
  18711.  
  18712.  The construct 2>&1 is often used to redirect standard error to the same
  18713.  file as standard output.  Since the redirections take place beginning to
  18714.  end, the order of redirections is significant.  For example:
  18715.  
  18716.        ls > foo 2>&1
  18717.  
  18718.  directs both standard output and standard error to file foo.  However
  18719.  
  18720.        ls 2>&1 > foo
  18721.  
  18722.  only directs standard output to file foo because standard error was
  18723.  duplicated as standard output before standard output was directed to file
  18724.  foo.
  18725.  
  18726.  The <> operator is a feature first documented in the KornShell, but it
  18727.  has been silently present in both System V and BSD shells.  It could be
  18728.  useful in writing an application that worked with several terminals, and
  18729.  occasionally wanted to start up a shell.  That shell would in turn be
  18730.  unable to run applications that run from an ordinary controlling terminal  1
  18731.  unless it could make use of <> redirection.  The specific example is a     1
  18732.  historical version of the pager more, which reads from standard error to
  18733.  
  18734.  
  18735.                Copyright c 1991 IEEE.  All rights reserved.
  18736.       This is an unapproved IEEE Standards Draft, subject to change.
  18737.  
  18738.  
  18739.  
  18740.  
  18741.  
  18742.  254                                              3 Shell Command Language
  18743.  
  18744.  
  18745.  
  18746.  
  18747.  
  18748.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18749.  
  18750.  get its commands, so standard input and standard output are both
  18751.  available for their usual usage.  There is no way of saying the following
  18752.  in the shell without <>:
  18753.  
  18754.        cat food | more - >/dev/tty03 2<>/dev/tty03
  18755.  
  18756.  Another example of <> is one that opens /dev/tty on file descriptor 3 for
  18757.  reading and writing:
  18758.  
  18759.        exec 3<> /dev/tty
  18760.  
  18761.  An example of creating a lock file for a critical code region:
  18762.  
  18763.        set -C
  18764.        until   2> /dev/null > lockfile
  18765.        do      sleep 30
  18766.        done
  18767.        set +C
  18768.        _p_e_r_f_o_r_m _c_r_i_t_i_c_a_l _f_u_n_c_t_i_o_n
  18769.        rm lockfile
  18770.  
  18771.  Since /dev/null is not a regular file, no error is generated by
  18772.  redirecting to it in _n_o_c_l_o_b_b_e_r mode.
  18773.  
  18774.  The case of a missing delimiter at the end of a here-document is not
  18775.  specified.  This is considered an error in the script (one that sometimes
  18776.  can be difficult to diagnose), although some systems have treated end-
  18777.  of-file as an implicit delimiter.
  18778.  
  18779.  Tilde expansion is not performed on a here-document because the data is    1
  18780.  treated as if it were enclosed in double-quotes.                           1
  18781.  
  18782.  END_RATIONALE                                                              1
  18783.  
  18784.  
  18785.  
  18786.  3.8  Exit Status and Errors
  18787.  
  18788.  
  18789.  3.8.1  Consequences of Shell Errors
  18790.  
  18791.  For a noninteractive shell, an error condition encountered by a special
  18792.  built-in (see 3.14) or other type of utility shall cause the shell to
  18793.  write a diagnostic message to standard error and exit as shown in the
  18794.  following table:
  18795.  
  18796.                                      S_p_e_c_i_a_l__B_u_i_l_t_-_i_n_ O_t_h_e_r__U_t_i_l_i_t_i_e_s_
  18797.  
  18798.  
  18799.  
  18800.  
  18801.                Copyright c 1991 IEEE.  All rights reserved.
  18802.       This is an unapproved IEEE Standards Draft, subject to change.
  18803.  
  18804.  
  18805.  
  18806.  
  18807.  
  18808.  3.8 Exit Status and Errors                                            255
  18809.  
  18810.  
  18811.  
  18812.  
  18813.  
  18814.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18815.  
  18816.       Shell language syntax error       shall exit      shall exit
  18817.       Utility syntax error (option      shall exit    shall not exit
  18818.       or operand error)
  18819.       Redirection error                 shall exit    shall not exit
  18820.       Variable assignment error         shall exit    shall not exit
  18821.       Expansion error                   shall exit      shall exit
  18822.       Command not found                    n/a           may exit
  18823.       dot script not found              shall exit          n/a
  18824.  
  18825.  An ``expansion error'' is one that occurs when the shell expansions
  18826.  defined in 3.6 are carried out (e.g., ${x!y}, because ! is not a valid
  18827.  operator); an implementation may treat these as syntax errors if it is
  18828.  able to detect them during tokenization, rather than during expansion.
  18829.  
  18830.  If any of the errors shown as ``shall (may) exit'' occur in a subshell,
  18831.  the subshell shall (may) exit with a nonzero status, but the script
  18832.  containing the subshell shall not exit because of the error.
  18833.  
  18834.  In all of the cases shown in the table, an interactive shell shall write
  18835.  a diagnostic message to standard error without exiting.
  18836.  
  18837.  
  18838.  3.8.2  Exit Status for Commands
  18839.  
  18840.  Each command has an exit status that can influence the behavior of other
  18841.  shell commands.  The exit status of commands that are not utilities are
  18842.  documented in this subclause.  The exit status of the standard utilities
  18843.  are documented in their respective clauses.
  18844.  
  18845.  If a command is not found by the shell, the exit status shall be 127.  If  1
  18846.  the command name is found, but it is not an executable utility, the exit   1
  18847.  status shall be 126.  See 3.9.1.1.  Applications that invoke utilities     1
  18848.  without using the shell should use these exit status values to report      1
  18849.  similar errors.                                                            1
  18850.  
  18851.  If a command fails during word expansion or redirection, its exit status
  18852.  shall be greater than zero.
  18853.  
  18854.  Internally, for purposes of deciding if a command exits with a nonzero
  18855.  exit status, the shell shall recognize the entire status value retrieved
  18856.  for the command by the equivalent of the POSIX.1 {8} _w_a_i_t() function
  18857.  WEXITSTATUS macro.  When reporting the exit status with the special
  18858.  parameter ?, the shell shall report the full eight bits of exit status
  18859.  available.  The exit status of a command that terminated because it
  18860.  received a signal shall be reported as greater than 128.
  18861.  
  18862.  BEGIN_RATIONALE
  18863.  
  18864.  
  18865.  
  18866.  
  18867.                Copyright c 1991 IEEE.  All rights reserved.
  18868.       This is an unapproved IEEE Standards Draft, subject to change.
  18869.  
  18870.  
  18871.  
  18872.  
  18873.  
  18874.  256                                              3 Shell Command Language
  18875.  
  18876.  
  18877.  
  18878.  
  18879.  
  18880.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  18881.  
  18882.  3.8.3  Exit Status and Errors Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  18883.         _P_1_0_0_3._2)
  18884.  
  18885.  There is a historical difference in sh and ksh noninteractive error
  18886.  behavior.  When a command named in a script is not found, some
  18887.  implementations of sh exit immediately, but ksh continues with the next
  18888.  command.  Thus, POSIX.2 says that the shell ``may'' exit in this case.
  18889.  This puts a small burden on the programmer, who will have to test for
  18890.  successful completion following a command if it is important that the
  18891.  next command not be executed if the previous was not found.  If it is
  18892.  important for the command to have been found, it was probably also
  18893.  important for it to complete successfully.  The test for successful
  18894.  completion would not need to change.
  18895.  
  18896.  Historically, shells have returned an exit status of 128+_n, where _n
  18897.  represents the signal number.  Since signal numbers are not standardized,
  18898.  there is no portable way to determine which signal caused the
  18899.  termination.  Also, it is possible for a command to exit with a status in
  18900.  the same range of numbers that the shell would use to report that the
  18901.  command was terminated by a signal.  Implementations are encouraged to     1
  18902.  chose exit values greater than 256 to indicate programs that terminated    1
  18903.  by a signal so that the exit status cannot be confused with an exit        1
  18904.  status generated by a normal termination.                                  1
  18905.  
  18906.  Historical shells make the distinction between ``utility not found'' and   1
  18907.  ``utility found but cannot execute'' in their error messages.  By          1
  18908.  specifying two seldomly used exit status values for these cases, 127 and   1
  18909.  126 respectively, this gives an application the opportunity to make use    1
  18910.  of this distinction without having to parse an error message that would    1
  18911.  probably change from locale to locale.  The POSIX.2 command, env, nohup,   1
  18912.  and xargs utilities also have been specified to use this convention.       1
  18913.  
  18914.  When a command fails during word expansion or redirection, most
  18915.  historical implementations exit with a status of 1.  However, there was
  18916.  some sentiment that this value should probably be much higher, so that an
  18917.  application could distinguish this case from the more normal exit status
  18918.  values.  Thus, the language ``greater than zero'' was selected to allow
  18919.  either method to be implemented.
  18920.  
  18921.  END_RATIONALE
  18922.  
  18923.  
  18924.  
  18925.  
  18926.  
  18927.  
  18928.  
  18929.  
  18930.  
  18931.  
  18932.  
  18933.                Copyright c 1991 IEEE.  All rights reserved.
  18934.       This is an unapproved IEEE Standards Draft, subject to change.
  18935.  
  18936.  
  18937.  
  18938.  
  18939.  
  18940.  3.8 Exit Status and Errors                                            257
  18941.  
  18942.  
  18943.  
  18944.  
  18945.  
  18946.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  18947.  
  18948.  3.9  Shell Commands
  18949.  
  18950.  This clause describes the basic structure of shell commands.  The
  18951.  following command descriptions each describe a format of the command that
  18952.  is only used to aid the reader in recognizing the command type, and does
  18953.  not formally represent the syntax.  Each description discusses the
  18954.  semantics of the command; for a formal description of the command
  18955.  language, consult the grammar in 3.10.
  18956.  
  18957.  A _c_o_m_m_a_n_d is one of the following:
  18958.  
  18959.      - _s_i_m_p_l_e _c_o_m_m_a_n_d (see 3.9.1)
  18960.  
  18961.      - _p_i_p_e_l_i_n_e (see 3.9.2)
  18962.  
  18963.      - _l_i_s_t or _c_o_m_p_o_u_n_d-_l_i_s_t (see 3.9.3)
  18964.  
  18965.      - _c_o_m_p_o_u_n_d _c_o_m_m_a_n_d (see 3.9.4)
  18966.  
  18967.      - _f_u_n_c_t_i_o_n _d_e_f_i_n_i_t_i_o_n (see 3.9.5).
  18968.  
  18969.  Unless otherwise stated, the exit status of a command is that of the last
  18970.  simple command executed by the command.  There is no limit on the size of
  18971.  any shell command other than that imposed by the underlying system
  18972.  (memory constraints, {ARG_MAX}, etc.).
  18973.  
  18974.  BEGIN_RATIONALE
  18975.  
  18976.  
  18977.  3.9.0.1  Shell Commands Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  18978.           _P_1_0_0_3._2)
  18979.  
  18980.  A description of an ``empty command'' was removed from an earlier draft    1
  18981.  because it is only relevant in the cases of sh -c  "", system(""), or an   1
  18982.  empty shell-script file (such as the implementation of true on some        1
  18983.  historical systems).  Since it is no longer mentioned in POSIX.2, it       1
  18984.  falls into the silently unspecified category of behavior where             1
  18985.  implementations can continue to operate as they have historically, but     1
  18986.  conforming applications will not construct empty commands.  (However,      1
  18987.  note that sh does explicitly state an exit status for an empty string or   1
  18988.  file.)  In an interactive session or a script with other commands, extra
  18989.  <newline>s or semicolons, such as
  18990.  
  18991.        $ false
  18992.        $
  18993.        $ echo $?
  18994.        1
  18995.  
  18996.  would not qualify as the empty command described here because they would
  18997.  be consumed by other parts of the grammar.
  18998.  
  18999.                Copyright c 1991 IEEE.  All rights reserved.
  19000.       This is an unapproved IEEE Standards Draft, subject to change.
  19001.  
  19002.  
  19003.  
  19004.  
  19005.  
  19006.  258                                              3 Shell Command Language
  19007.  
  19008.  
  19009.  
  19010.  
  19011.  
  19012.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19013.  
  19014.  END_RATIONALE
  19015.  
  19016.  
  19017.  3.9.1  Simple Commands
  19018.  
  19019.  A _s_i_m_p_l_e _c_o_m_m_a_n_d is a sequence of optional variable assignments and
  19020.  redirections, in any sequence, optionally followed by words and
  19021.  redirections, terminated by a control operator.
  19022.  
  19023.  When a given simple command is required to be executed (i.e., when any     1
  19024.  conditional construct such as an AND-OR list or a case statement has not   1
  19025.  bypassed the simple command), the following expansions, assignments, and   1
  19026.  redirections shall all be performed from the beginning of the command
  19027.  text to the end.
  19028.  
  19029.      (1)  The words that are recognized as variable assignments or
  19030.           redirections according to 3.10.2 are saved for processing in
  19031.           steps (3) and (4).
  19032.  
  19033.      (2)  The words that are not variable assignments or redirections
  19034.           shall be expanded.  If any fields remain following their
  19035.           expansion, the first field shall be considered the command name,
  19036.           and remaining fields shall be the arguments for the command.
  19037.  
  19038.      (3)  Redirections shall be performed as described in 3.7.
  19039.  
  19040.      (4)  Each variable assignment shall be expanded for tilde expansion,
  19041.           parameter expansion, command substitution, arithmetic expansion,
  19042.           and quote removal prior to assigning the value.
  19043.  
  19044.  In the preceding list, the order of steps (3) and (4) may be reversed for
  19045.  the processing of special built-in utilities.  See 3.14.
  19046.  
  19047.  If no command name results, variable assignments shall affect the current
  19048.  execution environment.  Otherwise, the variable assignments shall be
  19049.  exported for the execution environment of the command and shall not
  19050.  affect the current execution environment (except for special built-ins).
  19051.  If any of the variable assignments attempt to assign a value to a read-
  19052.  only variable, a variable assignment error shall occur.  See 3.8.1 for
  19053.  the consequences of these errors.
  19054.  
  19055.  If there is no command name, any redirections shall be performed in a
  19056.  subshell environment; it is unspecified whether this subshell environment
  19057.  is the same one as that used for a command substitution within the
  19058.  command.  [To affect the current execution environment, see exec
  19059.  (3.14.6)].  If any of the redirections performed in the current shell
  19060.  execution environment fail, the command shall immediately fail with an
  19061.  exit status greater than zero, and the shell shall write an error message
  19062.  indicating the failure.  See 3.8.1 for the consequences of these failures
  19063.  
  19064.  
  19065.                Copyright c 1991 IEEE.  All rights reserved.
  19066.       This is an unapproved IEEE Standards Draft, subject to change.
  19067.  
  19068.  
  19069.  
  19070.  
  19071.  
  19072.  3.9 Shell Commands                                                    259
  19073.  
  19074.  
  19075.  
  19076.  
  19077.  
  19078.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19079.  
  19080.  on interactive and noninteractive shells.
  19081.  
  19082.  If there is a command name, execution shall continue as described in
  19083.  3.9.1.1.  If there is no command name, but the command contained a
  19084.  command substitution, the command shall complete with the exit status of
  19085.  the last command substitution performed.  Otherwise, the command shall
  19086.  complete with a zero exit status.
  19087.  
  19088.  BEGIN_RATIONALE
  19089.  
  19090.  3.9.1.0.1  Simple Commands Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  19091.             _P_1_0_0_3._2)
  19092.  
  19093.  The enumerated list is used only when the command is actually going to be  1
  19094.  executed.  For example, in:                                                1
  19095.  
  19096.        true || $foo *                                                       1
  19097.  
  19098.  no expansions are performed.                                               1
  19099.  
  19100.  The following example illustrates both how a variable assignment without
  19101.  a command name affects the current execution environment, and how an
  19102.  assignment with a command name only affects the execution environment of
  19103.  the command.
  19104.  
  19105.        $ x=red
  19106.        $ echo $x
  19107.        red
  19108.        $ export x
  19109.        $ sh -c 'echo $x'
  19110.        red
  19111.        $ x=blue sh -c 'echo $x'
  19112.        blue
  19113.        $ echo $x
  19114.        red
  19115.  
  19116.  This next example illustrates that redirections without a command name
  19117.  are still performed.
  19118.  
  19119.        $ ls foo
  19120.        ls: foo: no such file or directory
  19121.        $ > foo
  19122.        $ ls foo
  19123.        foo
  19124.  
  19125.  Historical practice is for a command without a command name, but that
  19126.  includes a command substitution, to have an exit status of the last
  19127.  command substitution that the shell performed and some historical scripts
  19128.  rely on this.  For example:
  19129.  
  19130.  
  19131.                Copyright c 1991 IEEE.  All rights reserved.
  19132.       This is an unapproved IEEE Standards Draft, subject to change.
  19133.  
  19134.  
  19135.  
  19136.  
  19137.  
  19138.  260                                              3 Shell Command Language
  19139.  
  19140.  
  19141.  
  19142.  
  19143.  
  19144.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19145.  
  19146.        if      x=$(_c_o_m_m_a_n_d)
  19147.        then    ...
  19148.        fi
  19149.  
  19150.  An example of redirections without a command name being performed in a
  19151.  subshell shows that the here-document does not disrupt the standard input
  19152.  of the while loop:
  19153.  
  19154.        IFS=:
  19155.        while   read a b
  19156.        do      echo $a
  19157.                <<-eof
  19158.                Hello
  19159.                eof
  19160.        done </etc/passwd
  19161.  
  19162.  Some examples of commands without command names in AND/OR lists:
  19163.  
  19164.        > foo || {
  19165.                echo "error: foo cannot be created" >&2                      1
  19166.                exit 1                                                       1
  19167.        }
  19168.  
  19169.        # set saved if /vmunix.save exists
  19170.        test -f /vmunix.save && saved=1
  19171.  
  19172.  Command substitution and redirections without command names both occur in
  19173.  subshells, but they are not the same ones.  For example, in:               1
  19174.  
  19175.        exec 3> file
  19176.        var=$(echo foo >&3) 3>&1
  19177.  
  19178.  it is unspecified whether foo will be echoed to the file or to standard
  19179.  output.
  19180.  
  19181.  END_RATIONALE
  19182.  
  19183.  
  19184.  3.9.1.1  Command Search and Execution
  19185.  
  19186.  If a simple command results in a command name and an optional list of
  19187.  arguments, the following actions shall be performed.
  19188.  
  19189.      (1)  If the command name does not contain any slashes, the first
  19190.           successful step in the following sequence shall occur:
  19191.  
  19192.            (a)  If the command name matches the name of a special built-in
  19193.                 utility, that special built-in utility shall be invoked.
  19194.  
  19195.  
  19196.  
  19197.                Copyright c 1991 IEEE.  All rights reserved.
  19198.       This is an unapproved IEEE Standards Draft, subject to change.
  19199.  
  19200.  
  19201.  
  19202.  
  19203.  
  19204.  3.9 Shell Commands                                                    261
  19205.  
  19206.  
  19207.  
  19208.  
  19209.  
  19210.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19211.  
  19212.            (b)  If the command name matches the name of a function known
  19213.                 to this shell, the function shall be invoked as described
  19214.                 in 3.9.5.  [If the implementation has provided a standard
  19215.                 utility in the form of a function, it shall not be
  19216.                 recognized at this point.  It shall be invoked in
  19217.                 conjunction with the path search in step (1)(d).]
  19218.  
  19219.            (c)  If the command name matches the name of a utility listed
  19220.                 in Table 2-2 (see 2.3), that utility shall be invoked.
  19221.  
  19222.            (d)  Otherwise, the command shall be searched for using the
  19223.                 PATH environment variable as described in 2.6:
  19224.  
  19225.                  [1]  If the search is successful:
  19226.  
  19227.                        [a]  If the system has implemented the utility as a
  19228.                             regular built-in or as a shell function, it
  19229.                             shall be invoked at this point in the path
  19230.                             search.
  19231.  
  19232.                        [b]  Otherwise, the shell shall execute the utility  1
  19233.                             in a separate utility environment (see 3.12)    1
  19234.                             with actions equivalent to calling the          1
  19235.                             POSIX.1 {8} _e_x_e_c_v_e() function with the _p_a_t_h
  19236.                             argument set to the pathname resulting from
  19237.                             the search, _a_r_g_0 set to the command name, and
  19238.                             the remaining arguments set to the operands,
  19239.                             if any.
  19240.  
  19241.                             If the _e_x_e_c_v_e() function fails due to an error
  19242.                             equivalent to the POSIX.1 {8} error [ENOEXEC],
  19243.                             the shell shall execute a command equivalent
  19244.                             to having a shell invoked with the command
  19245.                             name as its first operand, along with any
  19246.                             remaining arguments passed along.  If the
  19247.                             executable file is not a text file, the shell
  19248.                             may bypass this command execution, write an
  19249.                             error message, and return an exit status of     1
  19250.                             126.                                            1
  19251.  
  19252.                       Once a utility has been searched for and found
  19253.                       (either as a result of this specific search or as
  19254.                       part of an unspecified shell startup activity), an
  19255.                       implementation may remember its location and need
  19256.                       not search for the utility again unless the PATH
  19257.                       variable has been the subject of an assignment.  If
  19258.                       the remembered location fails for a subsequent
  19259.                       invocation, the shell shall repeat the search to
  19260.                       find the new location for the utility, if any.
  19261.  
  19262.  
  19263.                Copyright c 1991 IEEE.  All rights reserved.
  19264.       This is an unapproved IEEE Standards Draft, subject to change.
  19265.  
  19266.  
  19267.  
  19268.  
  19269.  
  19270.  262                                              3 Shell Command Language
  19271.  
  19272.  
  19273.  
  19274.  
  19275.  
  19276.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19277.  
  19278.                  [2]  If the search is unsuccessful, the command shall
  19279.                       fail with an exit status of 127 and the shell shall
  19280.                       write an error message.
  19281.  
  19282.      (2)  If the command name does contain slashes, the shell shall
  19283.           execute the utility in a separate utility environment with        1
  19284.           actions equivalent to calling the POSIX.1 {8} _e_x_e_c_v_e() function   1
  19285.           with the _p_a_t_h and _a_r_g_0 arguments set to the command name, and
  19286.           the remaining arguments set to the operands, if any.
  19287.  
  19288.           If the _e_x_e_c_v_e() function fails due to an error equivalent to the
  19289.           POSIX.1 {8} error [ENOEXEC], the shell shall execute a command
  19290.           equivalent to having a shell invoked with the command name as
  19291.           its first operand, along with any remaining arguments passed
  19292.           along.  If the executable file is not a text file, the shell may
  19293.           bypass this command execution, write an error message, and
  19294.           return an exit status of 126.                                     1
  19295.  
  19296.  BEGIN_RATIONALE
  19297.  
  19298.  3.9.1.1.1  Command Search and Execution Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t
  19299.             _a _p_a_r_t _o_f _P_1_0_0_3._2)
  19300.  
  19301.  This description requires that the shell can execute shell scripts
  19302.  directly, even if the underlying system does not support the common #!
  19303.  interpreter convention.  That is, if file foo contains shell commands and
  19304.  is executable, the following will execute foo:
  19305.  
  19306.        ./foo
  19307.  
  19308.  The command search shown here does not match all historical
  19309.  implementations.  A more typical sequence has been:
  19310.  
  19311.      - Any built-in, special or regular.
  19312.  
  19313.      - Functions.
  19314.  
  19315.      - Path search for executable files.
  19316.  
  19317.  But there are problems with this sequence.  Since the programmer has no
  19318.  idea in advance which utilities might have been built into the shell, a
  19319.  function cannot be used to portably override a utility of the same name.
  19320.  (For example, a function named cd cannot be written for many historical
  19321.  systems.)  Furthermore, the PATH variable is partially ineffective in
  19322.  this case and only a pathname with a slash can be used to ensure a
  19323.  specific executable file is invoked.
  19324.  
  19325.  The sequence selected for POSIX.2 acknowledges that special built-ins
  19326.  cannot be overridden, but gives the programmer full control over which
  19327.  
  19328.  
  19329.                Copyright c 1991 IEEE.  All rights reserved.
  19330.       This is an unapproved IEEE Standards Draft, subject to change.
  19331.  
  19332.  
  19333.  
  19334.  
  19335.  
  19336.  3.9 Shell Commands                                                    263
  19337.  
  19338.  
  19339.  
  19340.  
  19341.  
  19342.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19343.  
  19344.  versions of other utilities are executed.  It provides a means of
  19345.  suppressing function lookup (via the command utility; see 4.12) for the
  19346.  user's own functions and ensures that any regular built-ins or functions
  19347.  provided by the implementation are under the control of the path search.
  19348.  The mechanisms for associating built-ins or functions with executable
  19349.  files in the path are not specified by POSIX.2, but the wording requires
  19350.  that if either is implemented, the application will not be able to
  19351.  distinguish a function or built-in from an executable (other than in
  19352.  terms of performance, presumably).  The implementation must ensure that
  19353.  all effects specified by POSIX.2 resulting from the invocation of the
  19354.  regular built-in or function (interaction with the environment,
  19355.  variables, traps, etc.) are identical to those resulting from the
  19356.  invocation of an executable file.
  19357.  
  19358.  Example:  Consider three versions of the ls utility:
  19359.  
  19360.      - The application includes a shell function named ls.
  19361.  
  19362.      - The user writes her own utility named ls and puts it in /hsa/bin.
  19363.  
  19364.      - The example implementation provides ls as a regular shell built-in
  19365.        that will be invoked (either by the shell or directly by _e_x_e_c) when
  19366.        the path search reaches the directory /posix/bin.
  19367.  
  19368.  If PATH=/posix/bin, various invocations yield different versions of ls:
  19369.  
  19370.                      Invocation                        Version of ls
  19371.    _______________________________________________   __________________
  19372.    ls (from within application script)               (1) function
  19373.    command ls (from within application script)       (3) built-in
  19374.    ls (from within makefile called by application)   (3) built-in
  19375.    system("ls")                                      (3) built-in
  19376.    PATH="/hsa/bin:$PATH" ls                          (2) user's version
  19377.  
  19378.  After the _e_x_e_c_v_e() failure described, the shell normally executes the
  19379.  file as a shell script.  Some implementations, however, attempt to detect
  19380.  whether the file is actually a script and not an executable from some
  19381.  other architecture.  The method used by the KornShell is allowed by the
  19382.  text that indicates nontext files may be bypassed.
  19383.  
  19384.  END_RATIONALE
  19385.  
  19386.  
  19387.  3.9.2  Pipelines
  19388.  
  19389.  A _p_i_p_e_l_i_n_e is a sequence of one or more commands separated by the control
  19390.  operator |.  The standard output of all but the last command shall be
  19391.  connected to the standard input of the next command.
  19392.  
  19393.  
  19394.  
  19395.                Copyright c 1991 IEEE.  All rights reserved.
  19396.       This is an unapproved IEEE Standards Draft, subject to change.
  19397.  
  19398.  
  19399.  
  19400.  
  19401.  
  19402.  264                                              3 Shell Command Language
  19403.  
  19404.  
  19405.  
  19406.  
  19407.  
  19408.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19409.  
  19410.  The format for a pipeline is:
  19411.  
  19412.        [!] _c_o_m_m_a_n_d_1 [ | _c_o_m_m_a_n_d_2 ...]
  19413.  
  19414.  The standard output of _c_o_m_m_a_n_d_1 shall be connected to the standard input
  19415.  of _c_o_m_m_a_n_d_2. The standard input, standard output, or both of a command
  19416.  shall be considered to be assigned by the pipeline before any redirection
  19417.  specified by redirection operators that are part of the command (see
  19418.  3.7).
  19419.  
  19420.  If the pipeline is not in the background (see 3.9.3.1), the shell shall
  19421.  wait for the last command specified in the pipeline to complete, and may
  19422.  also wait for all commands to complete.
  19423.  
  19424.  _E_x_i_t__S_t_a_t_u_s
  19425.  
  19426.  If the reserved word ! does not precede the pipeline, the exit status
  19427.  shall be the exit status of the last command specified in the pipeline.
  19428.  Otherwise, the exit status is the logical NOT of the exit status of the
  19429.  last command.  That is, if the last command returns zero, the exit status
  19430.  shall be 1; if the last command returns greater than zero, the exit
  19431.  status is zero.
  19432.  
  19433.  BEGIN_RATIONALE
  19434.  
  19435.  
  19436.  3.9.2.1  Pipelines Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  19437.  
  19438.  Because pipeline assignment of standard input or standard output or both
  19439.  takes place before redirection, it can be modified by redirection.  For
  19440.  example:
  19441.  
  19442.        $ command1 2>&1 | command2
  19443.  
  19444.  sends both the standard output and standard error of command1 to the
  19445.  standard input of command2.
  19446.  
  19447.  The reserved word ! was added to allow more flexible testing using AND
  19448.  and OR lists.
  19449.  
  19450.  It was suggested that it would be better to return a nonzero value if any
  19451.  command in the pipeline terminates with nonzero status (perhaps the
  19452.  bitwise OR of all return values).  However, the choice of the last-
  19453.  specified command semantics are historical practice and would cause
  19454.  application breakage if changed.  An example of historical (and POSIX.2)
  19455.  behavior:
  19456.  
  19457.  
  19458.  
  19459.  
  19460.  
  19461.                Copyright c 1991 IEEE.  All rights reserved.
  19462.       This is an unapproved IEEE Standards Draft, subject to change.
  19463.  
  19464.  
  19465.  
  19466.  
  19467.  
  19468.  3.9 Shell Commands                                                    265
  19469.  
  19470.  
  19471.  
  19472.  
  19473.  
  19474.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19475.  
  19476.        $ sleep 5 | (exit 4)
  19477.        $ echo $?
  19478.        4
  19479.        $ (exit 4) | sleep 5                                                 1
  19480.        $ echo $?                                                            1
  19481.        0                                                                    1
  19482.  
  19483.  END_RATIONALE
  19484.  
  19485.  
  19486.  3.9.3  Lists
  19487.  
  19488.  An _A_N_D-_O_R-_l_i_s_t is a sequence of one or more pipelines separated by the
  19489.  operators
  19490.  
  19491.        &&    ||
  19492.  
  19493.  A _l_i_s_t is a sequence of one or more AND-OR-lists separated by the
  19494.  operators
  19495.  
  19496.        ;    &
  19497.  
  19498.  and optionally terminated by
  19499.  
  19500.        ;    &    <newline>
  19501.  
  19502.  The operators && and || shall have equal precedence and shall be
  19503.  evaluated from beginning to end.
  19504.  
  19505.  A ; or <newline> terminator shall cause the preceding AND-OR-list to be
  19506.  executed sequentially; an & shall cause asynchronous execution of the
  19507.  preceding AND-OR-list.
  19508.  
  19509.  The term _c_o_m_p_o_u_n_d-_l_i_s_t is derived from the grammar in 3.10; it is
  19510.  equivalent to a sequence of _l_i_s_t_s, separated by <newline>s, that can be
  19511.  preceded or followed by an arbitrary number of <newline>s.
  19512.  
  19513.  BEGIN_RATIONALE
  19514.  
  19515.  3.9.3.0.1  Lists Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  19516.  
  19517.  The equal precedence of && and || is historical practice.  The developers
  19518.  of the standard evaluated the model used more frequently in high level
  19519.  programming languages, such as C, to allow the shell logical operators to
  19520.  be used for complex expressions in an unambiguous way, but could not in
  19521.  the end allow existing scripts to break in the subtle way unequal
  19522.  precedence might cause.  Some arguments were posed concerning the { } or
  19523.  ( ) groupings that are required historically.  There are some
  19524.  disadvantages to these groupings:
  19525.  
  19526.  
  19527.                Copyright c 1991 IEEE.  All rights reserved.
  19528.       This is an unapproved IEEE Standards Draft, subject to change.
  19529.  
  19530.  
  19531.  
  19532.  
  19533.  
  19534.  266                                              3 Shell Command Language
  19535.  
  19536.  
  19537.  
  19538.  
  19539.  
  19540.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19541.  
  19542.      - The ( ) can be expensive, as they spawn other processes on some
  19543.        systems.  This performance concern is primarily an implementation
  19544.        issue.
  19545.  
  19546.      - The { } braces are not operators (they are reserved words) and
  19547.        require a trailing space after each {, and a semicolon before each
  19548.        }.  Most programmers (and certainly interactive users) have avoided
  19549.        braces as grouping constructs because of the irritating syntax
  19550.        required.  Braces were not changed to operators because that would
  19551.        generate compatibility issues even greater than the precedence
  19552.        question; braces appear outside the context of a keyword in many
  19553.        shell scripts.
  19554.  
  19555.  An example reiterates the precedence of the lists as they associate from   1
  19556.  beginning to end.  Both of the following commands write solely bar to      1
  19557.  standard output:                                                           1
  19558.  
  19559.        false && echo foo || echo bar                                        1
  19560.        true || echo foo && echo bar                                         1
  19561.  
  19562.  The following is an example that illustrates <newline>s in compound-
  19563.  lists:
  19564.  
  19565.        while
  19566.                # a couple of newlines
  19567.  
  19568.                # a list
  19569.                date && who || ls; cat file
  19570.                # a couple of newlines
  19571.  
  19572.                # another list
  19573.                wc file > output & true
  19574.  
  19575.        do
  19576.                # 2 lists
  19577.                ls
  19578.                cat file
  19579.        done
  19580.  
  19581.  END_RATIONALE
  19582.  
  19583.  
  19584.  3.9.3.1  Asynchronous Lists
  19585.  
  19586.  If a command is terminated by the control operator ampersand (&), the
  19587.  shell shall execute the command asynchronously in a subshell.  This means
  19588.  that the shell shall not wait for the command to finish before executing
  19589.  the next command.
  19590.  
  19591.  
  19592.  
  19593.                Copyright c 1991 IEEE.  All rights reserved.
  19594.       This is an unapproved IEEE Standards Draft, subject to change.
  19595.  
  19596.  
  19597.  
  19598.  
  19599.  
  19600.  3.9 Shell Commands                                                    267
  19601.  
  19602.  
  19603.  
  19604.  
  19605.  
  19606.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19607.  
  19608.  The format for running a command in background is:
  19609.  
  19610.        _c_o_m_m_a_n_d_1 & [_c_o_m_m_a_n_d_2 & ...]
  19611.  
  19612.  The standard input for an asynchronous list, before any explicit
  19613.  redirections are performed, shall be considered to be assigned to a file
  19614.  that has the same properties as /dev/null.  If it is an interactive
  19615.  shell, this need not happen.  In all cases, explicit redirection of
  19616.  standard input shall override this activity.
  19617.  
  19618.  When an element of an asynchronous list (the portion of the list ended by  1
  19619.  an ampersand, such as _c_o_m_m_a_n_d_1, above) is started by the shell, the        1
  19620.  process ID of the last command in the asynchronous list element shall      1
  19621.  become known in the current shell execution environment; see 3.12.  This
  19622.  process ID shall remain known until:
  19623.  
  19624.      - The command terminates and the application waits for the process
  19625.        ID, or
  19626.  
  19627.      - Another asynchronous list is invoked before $! (corresponding to     1
  19628.        the previous asynchronous list) is expanded in the current           1
  19629.        execution environment.                                               1
  19630.  
  19631.  The implementation need not retain more than the {CHILD_MAX} most recent   1
  19632.  entries in its list of known process IDs in the current shell execution    1
  19633.  environment.                                                               1
  19634.  
  19635.  _E_x_i_t__S_t_a_t_u_s
  19636.  
  19637.  The exit status of an asynchronous list shall be zero.
  19638.  
  19639.  BEGIN_RATIONALE
  19640.  
  19641.  3.9.3.1.1  Asynchronous Lists Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  19642.             _P_1_0_0_3._2)
  19643.  
  19644.  The grammar treats a construct such as                                     1
  19645.  
  19646.        foo & bar & bam &                                                    1
  19647.  
  19648.  as one ``asynchronous list,'' but since the status of each element is      1
  19649.  tracked by the shell, the term ``element of an asynchronous list'' was     1
  19650.  introduced to identify just one of the foo, bar, bam portions of the       1
  19651.  overall list.                                                              1
  19652.  
  19653.  Unless the implementation has an internal limit, such as {CHILD_MAX}, on   1
  19654.  the retained process IDs, it would require unbounded memory for the        1
  19655.  following example:                                                         1
  19656.  
  19657.  
  19658.  
  19659.                Copyright c 1991 IEEE.  All rights reserved.
  19660.       This is an unapproved IEEE Standards Draft, subject to change.
  19661.  
  19662.  
  19663.  
  19664.  
  19665.  
  19666.  268                                              3 Shell Command Language
  19667.  
  19668.  
  19669.  
  19670.  
  19671.  
  19672.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19673.  
  19674.        while true                                                           1
  19675.        do      foo & echo $!                                                1
  19676.        done                                                                 1
  19677.  
  19678.  The treatment of the signals SIGINT and SIGQUIT with asynchronous lists
  19679.  is described in 3.11.
  19680.  
  19681.  Since the connection of the input to the equivalent of /dev/null is
  19682.  considered to occur before redirections, the following script would
  19683.  produce no output:
  19684.  
  19685.        exec < /etc/passwd
  19686.        cat <&0 &
  19687.        wait
  19688.  
  19689.  END_RATIONALE
  19690.  
  19691.  
  19692.  3.9.3.2  Sequential Lists
  19693.  
  19694.  Commands that are separated by a semicolon (;) shall be executed
  19695.  sequentially.
  19696.  
  19697.  The format for executing commands sequentially is:
  19698.  
  19699.        _c_o_m_m_a_n_d_1 [; _c_o_m_m_a_n_d_2] ...
  19700.  
  19701.  Each command shall be expanded and executed in the order specified.
  19702.  
  19703.  _E_x_i_t__S_t_a_t_u_s
  19704.  
  19705.  The exit status of a sequential list shall be the exit status of the last
  19706.  command in the list.
  19707.  
  19708.  3.9.3.3  AND Lists
  19709.  
  19710.  The control operator && shall denote an AND list.  The format is:
  19711.  
  19712.        _c_o_m_m_a_n_d_1 [ && _c_o_m_m_a_n_d_2] ...
  19713.  
  19714.  First _c_o_m_m_a_n_d_1 is executed.  If its exit status is zero, _c_o_m_m_a_n_d_2 is
  19715.  executed, and so on until a command has a nonzero exit status or there
  19716.  are no more commands left to execute.  The commands shall be expanded
  19717.  only if they are executed.
  19718.  
  19719.  _E_x_i_t__S_t_a_t_u_s
  19720.  
  19721.  The exit status of an AND list shall be the exit status of the last
  19722.  command that is executed in the list.
  19723.  
  19724.  
  19725.                Copyright c 1991 IEEE.  All rights reserved.
  19726.       This is an unapproved IEEE Standards Draft, subject to change.
  19727.  
  19728.  
  19729.  
  19730.  
  19731.  
  19732.  3.9 Shell Commands                                                    269
  19733.  
  19734.  
  19735.  
  19736.  
  19737.  
  19738.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19739.  
  19740.  3.9.3.4  OR Lists
  19741.  
  19742.  The control operator || shall denote an OR List.  The format is:
  19743.  
  19744.        _c_o_m_m_a_n_d_1 [ || _c_o_m_m_a_n_d_2] ...
  19745.  
  19746.  First, _c_o_m_m_a_n_d_1 is executed.  If its exit status is nonzero, _c_o_m_m_a_n_d_2 is
  19747.  executed, and so on until a command has a zero exit status or there are
  19748.  no more commands left to execute.
  19749.  
  19750.  _E_x_i_t__S_t_a_t_u_s
  19751.  
  19752.  The exit status of an OR list shall be the exit status of the last
  19753.  command that is executed in the list.
  19754.  
  19755.  
  19756.  3.9.4  Compound Commands
  19757.  
  19758.  The shell has several programming constructs that are _c_o_m_p_o_u_n_d _c_o_m_m_a_n_d_s,
  19759.  which provide control flow for commands.  Each of these compound commands
  19760.  has a reserved word or control operator at the beginning, and a
  19761.  corresponding terminator reserved word or operator at the end.  In
  19762.  addition, each can be followed by redirections on the same line as the
  19763.  terminator.  Each redirection shall apply to all the commands within the
  19764.  compound command that do not explicitly override that redirection.
  19765.  
  19766.  
  19767.  3.9.4.1  Grouping Commands
  19768.  
  19769.  The format for grouping commands is as follows:
  19770.  
  19771.     (_c_o_m_p_o_u_n_d-_l_i_s_t)       Execute _c_o_m_p_o_u_n_d-_l_i_s_t in a subshell environment;
  19772.                           see 3.12.  Variable assignments and built-in
  19773.                           commands that affect the environment shall not
  19774.                           remain in effect after the list finishes.
  19775.  
  19776.     { _c_o_m_p_o_u_n_d-_l_i_s_t;}     Execute _c_o_m_p_o_u_n_d-_l_i_s_t in the current process
  19777.                           environment.
  19778.  
  19779.  _E_x_i_t__S_t_a_t_u_s
  19780.  
  19781.  The exit status of a grouping command shall be the exit status of _l_i_s_t.
  19782.  
  19783.  BEGIN_RATIONALE
  19784.  
  19785.  
  19786.  
  19787.  
  19788.  
  19789.  
  19790.  
  19791.                Copyright c 1991 IEEE.  All rights reserved.
  19792.       This is an unapproved IEEE Standards Draft, subject to change.
  19793.  
  19794.  
  19795.  
  19796.  
  19797.  
  19798.  270                                              3 Shell Command Language
  19799.  
  19800.  
  19801.  
  19802.  
  19803.  
  19804.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19805.  
  19806.  3.9.4.1.1  Grouping Commands Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  19807.             _P_1_0_0_3._2)
  19808.  
  19809.  The semicolon shown in { _c_o_m_p_o_u_n_d-_l_i_s_t;} is an example of a control
  19810.  operator delimiting the } reserved word.  Other delimiters are possible,
  19811.  as shown in 3.10; <newline> is frequently used.
  19812.  
  19813.  A proposal was made to use the <do-done> construct in all cases where
  19814.  command grouping performed in the current process environment is
  19815.  performed, identifying it as a construct for the grouping commands, as
  19816.  well as for shell functions.  This was not included because the shell
  19817.  already has a grouping construct for this purpose ({ }), and changing it
  19818.  would have been counter-productive.
  19819.  
  19820.  END_RATIONALE
  19821.  
  19822.  
  19823.  3.9.4.2  for Loop
  19824.  
  19825.  The for loop shall execute a sequence of commands for each member in a
  19826.  list of _i_t_e_m_s.  The for loop requires that the _r_e_s_e_r_v_e_d _w_o_r_d_s do and done
  19827.  be used to delimit the sequence of commands.
  19828.  
  19829.  The format for the for loop is as follows.
  19830.  
  19831.        for _n_a_m_e [ in _w_o_r_d ... ]
  19832.        do
  19833.                _c_o_m_p_o_u_n_d-_l_i_s_t
  19834.        done
  19835.  
  19836.  First, the list of words following in shall be expanded to generate a
  19837.  list of items.  Then, the variable _n_a_m_e shall be set to each item, in
  19838.  turn, and the _c_o_m_p_o_u_n_d-_l_i_s_t executed each time.  If no items result from
  19839.  the expansion, the _c_o_m_p_o_u_n_d-_l_i_s_t shall not be executed.  Omitting
  19840.  
  19841.        in _w_o_r_d ...
  19842.  
  19843.  is equivalent to
  19844.  
  19845.        in "$@"
  19846.  
  19847.  _E_x_i_t__S_t_a_t_u_s
  19848.  
  19849.  The exit status of a for command shall be the exit status of the last
  19850.  command that executes.  If there are no items, the exit status shall be
  19851.  zero.
  19852.  
  19853.  BEGIN_RATIONALE
  19854.  
  19855.  
  19856.  
  19857.                Copyright c 1991 IEEE.  All rights reserved.
  19858.       This is an unapproved IEEE Standards Draft, subject to change.
  19859.  
  19860.  
  19861.  
  19862.  
  19863.  
  19864.  3.9 Shell Commands                                                    271
  19865.  
  19866.  
  19867.  
  19868.  
  19869.  
  19870.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  19871.  
  19872.  3.9.4.2.1  for Loop Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  19873.  
  19874.  The format is shown with generous usage of <newline>s.  See the grammar
  19875.  in 3.10 for a precise description of where <newline>s and semicolons can
  19876.  be interchanged.
  19877.  
  19878.  Some historical implementations support { and } as substitutes for do and
  19879.  done.  The working group chose to omit them, even as an obsolescent
  19880.  feature.  (Note that these substitutes were only for the for command; the
  19881.  while and until commands could not use them historically, because they     1
  19882.  are followed by compound-lists that may contain {...} grouping commands    1
  19883.  themselves                                                                 1
  19884.  
  19885.  The reserved word pair do ...  done was selected rather than do ...  od
  19886.  (which would have matched the spirit of if ...  fi and case ...  esac)
  19887.  because od is a commonly-used utility name and this would have been an
  19888.  unacceptable choice.
  19889.  
  19890.  END_RATIONALE
  19891.  
  19892.  
  19893.  3.9.4.3  case Conditional Construct
  19894.  
  19895.  The conditional construct case shall execute the _c_o_m_p_o_u_n_d-_l_i_s_t
  19896.  corresponding to the first one of several _p_a_t_t_e_r_n_s (see 3.13) that is
  19897.  matched by the string resulting from the tilde expansion, parameter
  19898.  expansion, command substitution, and arithmetic expansion and quote
  19899.  removal of the given word.  The reserved word in shall denote the
  19900.  beginning of the patterns to be matched.  Multiple patterns with the same
  19901.  _c_o_m_p_o_u_n_d-_l_i_s_t are delimited by the | symbol.  The control operator )
  19902.  terminates a list of patterns corresponding to a given action.  The
  19903.  _c_o_m_p_o_u_n_d-_l_i_s_t for each list of patterns is terminated with ;;.  The case
  19904.  construct terminates with the reserved word esac (case reversed).
  19905.  
  19906.  The format for the case construct is as follows.
  19907.  
  19908.        case _w_o_r_d in
  19909.             [(]_p_a_t_t_e_r_n_1)   _c_o_m_p_o_u_n_d-_l_i_s_t;;                                  2
  19910.             [(]_p_a_t_t_e_r_n_2|_p_a_t_t_e_r_n_3)_c_o_m_p_o_u_n_d-_l_i_s_t;;                            2
  19911.             ...
  19912.        esac
  19913.  
  19914.  The ;; is optional for the last _c_o_m_p_o_u_n_d-_l_i_s_t.
  19915.  
  19916.  Each pattern in a pattern list shall be expanded and compared against the
  19917.  expansion of _w_o_r_d.  After the first match, no more patterns shall be
  19918.  expanded, and the _c_o_m_p_o_u_n_d-_l_i_s_t shall be executed.  The order of
  19919.  expansion and comparing of patterns in a multiple pattern list is
  19920.  unspecified.
  19921.  
  19922.  
  19923.                Copyright c 1991 IEEE.  All rights reserved.
  19924.       This is an unapproved IEEE Standards Draft, subject to change.
  19925.  
  19926.  
  19927.  
  19928.  
  19929.  
  19930.  272                                              3 Shell Command Language
  19931.  
  19932.  
  19933.  
  19934.  
  19935.  
  19936.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  19937.  
  19938.  _E_x_i_t__S_t_a_t_u_s
  19939.  
  19940.  The exit status of case is zero if no patterns are matched.  Otherwise,
  19941.  the exit status shall be the exit status of the last command executed in
  19942.  the _c_o_m_p_o_u_n_d-_l_i_s_t.
  19943.  
  19944.  BEGIN_RATIONALE
  19945.  
  19946.  3.9.4.3.1  case Conditional Construct Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  19947.             _p_a_r_t _o_f _P_1_0_0_3._2)
  19948.  
  19949.  An optional open-parenthesis before _p_a_t_t_e_r_n was added to allow numerous    2
  19950.  historical KornShell scripts to conform.  At one time, using the leading   2
  19951.  parenthesis was required if the case statement were to be embedded within  2
  19952.  a $( ) command substitution; this is no longer the case with the POSIX     2
  19953.  shell.  Nevertheless, many existing scripts use the open-parenthesis, if   2
  19954.  only because it makes matching-parenthesis searching easier in vi and      2
  19955.  other editors.  This is a relatively simple implementation change that is  2
  19956.  fully upward compatible for all scripts.                                   2
  19957.  
  19958.  Consideration was given to requiring break inside the _c_o_m_p_o_u_n_d-_l_i_s_t to
  19959.  prevent falling through to the next pattern action list.  This was
  19960.  rejected as being nonexisting practice.  An interesting undocumented
  19961.  feature of the KornShell is that using ;& instead of ;; as a terminator
  19962.  causes the exact opposite behavior--the flow of control continues with
  19963.  the next _c_o_m_p_o_u_n_d-_l_i_s_t.
  19964.  
  19965.  The pattern "*", given as the last pattern in a case construct, is
  19966.  equivalent to the default case in a C-language switch statement
  19967.  
  19968.  The grammar shows that reserved words can be used as patterns, even if
  19969.  one is the first word on a line.  Obviously, the reserved word esac
  19970.  cannot be used in this manner.
  19971.  
  19972.  END_RATIONALE
  19973.  
  19974.  
  19975.  3.9.4.4  if Conditional Construct
  19976.  
  19977.  The if command shall execute a _c_o_m_p_o_u_n_d-_l_i_s_t and use its exit status to
  19978.  determine whether to execute another _c_o_m_p_o_u_n_d-_l_i_s_t.
  19979.  
  19980.  The format for the if construct is as follows.
  19981.  
  19982.  
  19983.  
  19984.  
  19985.  
  19986.  
  19987.  
  19988.  
  19989.                Copyright c 1991 IEEE.  All rights reserved.
  19990.       This is an unapproved IEEE Standards Draft, subject to change.
  19991.  
  19992.  
  19993.  
  19994.  
  19995.  
  19996.  3.9 Shell Commands                                                    273
  19997.  
  19998.  
  19999.  
  20000.  
  20001.  
  20002.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20003.  
  20004.        if _c_o_m_p_o_u_n_d-_l_i_s_t
  20005.        _t_h_e_n
  20006.                _c_o_m_p_o_u_n_d-_l_i_s_t
  20007.        [elif _c_o_m_p_o_u_n_d-_l_i_s_t
  20008.        _t_h_e_n
  20009.                _c_o_m_p_o_u_n_d-_l_i_s_t] ...
  20010.        [else
  20011.                _c_o_m_p_o_u_n_d-_l_i_s_t]
  20012.        fi
  20013.  
  20014.  The if _c_o_m_p_o_u_n_d-_l_i_s_t is executed; if its exit status is zero, the then
  20015.  _c_o_m_p_o_u_n_d-_l_i_s_t is executed and the command shall complete.  Otherwise,
  20016.  each elif _c_o_m_p_o_u_n_d-_l_i_s_t is executed, in turn, and if its exit status is
  20017.  zero, the then _c_o_m_p_o_u_n_d-_l_i_s_t is executed and the command shall complete.
  20018.  Otherwise, the else _c_o_m_p_o_u_n_d-_l_i_s_t is executed.
  20019.  
  20020.  _E_x_i_t__S_t_a_t_u_s
  20021.  
  20022.  The exit status of the if command shall be the exit status of the then or
  20023.  else _c_o_m_p_o_u_n_d-_l_i_s_t that was executed, or zero, if none was executed.
  20024.  
  20025.  BEGIN_RATIONALE
  20026.  
  20027.  3.9.4.4.1  if Conditional Construct Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  20028.             _p_a_r_t _o_f _P_1_0_0_3._2)
  20029.  
  20030.  The precise format for the command syntax is described in 3.10.
  20031.  
  20032.  END_RATIONALE
  20033.  
  20034.  
  20035.  3.9.4.5  while Loop
  20036.  
  20037.  The while loop continuously shall execute one _c_o_m_p_o_u_n_d-_l_i_s_t as long as
  20038.  another _c_o_m_p_o_u_n_d-_l_i_s_t has a zero exit status.
  20039.  
  20040.  The format of the while loop is as follows
  20041.  
  20042.        while _c_o_m_p_o_u_n_d-_l_i_s_t-_1
  20043.        _d_o
  20044.                _c_o_m_p_o_u_n_d-_l_i_s_t-_2
  20045.        _d_o_n_e
  20046.  
  20047.  The _c_o_m_p_o_u_n_d-_l_i_s_t-_1 shall be executed, and if it has a nonzero exit
  20048.  status, the while command shall complete.  Otherwise, the _c_o_m_p_o_u_n_d-_l_i_s_t-_2
  20049.  shall be executed, and the process shall repeat.
  20050.  
  20051.  
  20052.  
  20053.  
  20054.  
  20055.                Copyright c 1991 IEEE.  All rights reserved.
  20056.       This is an unapproved IEEE Standards Draft, subject to change.
  20057.  
  20058.  
  20059.  
  20060.  
  20061.  
  20062.  274                                              3 Shell Command Language
  20063.  
  20064.  
  20065.  
  20066.  
  20067.  
  20068.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20069.  
  20070.  _E_x_i_t__S_t_a_t_u_s
  20071.  
  20072.  The exit status of the while loop shall be the exit status of the last
  20073.  _c_o_m_p_o_u_n_d-_l_i_s_t-_2 executed, or zero if none was executed.
  20074.  
  20075.  BEGIN_RATIONALE
  20076.  
  20077.  3.9.4.5.1  while Loop Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  20078.             _P_1_0_0_3._2)
  20079.  
  20080.  The precise format for the command syntax is described in 3.10.
  20081.  
  20082.  END_RATIONALE
  20083.  
  20084.  
  20085.  3.9.4.6  until Loop
  20086.  
  20087.  The until loop continuously shall execute one _c_o_m_p_o_u_n_d-_l_i_s_t as long as
  20088.  another _c_o_m_p_o_u_n_d-_l_i_s_t has a nonzero exit status.
  20089.  
  20090.  The format of the until loop is as follows
  20091.  
  20092.        until _c_o_m_p_o_u_n_d-_l_i_s_t-_1
  20093.        _d_o
  20094.                _c_o_m_p_o_u_n_d-_l_i_s_t-_2
  20095.        _d_o_n_e
  20096.  
  20097.  The _c_o_m_p_o_u_n_d-_l_i_s_t-_1 shall be executed, and if it has a zero exit status,
  20098.  the until command shall complete.  Otherwise, the _c_o_m_p_o_u_n_d-_l_i_s_t-_2 shall
  20099.  be executed, and the process shall repeat.
  20100.  
  20101.  _E_x_i_t__S_t_a_t_u_s
  20102.  
  20103.  The exit status of the until loop shall be the exit status of the last
  20104.  _c_o_m_p_o_u_n_d-_l_i_s_t-_2 executed, or zero if none was executed.
  20105.  
  20106.  BEGIN_RATIONALE
  20107.  
  20108.  3.9.4.6.1  until Loop Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  20109.             _P_1_0_0_3._2)
  20110.  
  20111.  The precise format for the command syntax is described in 3.10.
  20112.  
  20113.  END_RATIONALE
  20114.  
  20115.  
  20116.  
  20117.  
  20118.  
  20119.  
  20120.  
  20121.                Copyright c 1991 IEEE.  All rights reserved.
  20122.       This is an unapproved IEEE Standards Draft, subject to change.
  20123.  
  20124.  
  20125.  
  20126.  
  20127.  
  20128.  3.9 Shell Commands                                                    275
  20129.  
  20130.  
  20131.  
  20132.  
  20133.  
  20134.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20135.  
  20136.  3.9.5  Function Definition Command
  20137.  
  20138.  A function is a user-defined name that is used as a simple command to
  20139.  call a compound command with new positional parameters.  A function is
  20140.  defined with a _f_u_n_c_t_i_o_n _d_e_f_i_n_i_t_i_o_n _c_o_m_m_a_n_d.
  20141.  
  20142.  The format of a function definition command is as follows:
  20143.  
  20144.        _f_n_a_m_e() _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d [_i_o-_r_e_d_i_r_e_c_t ...]
  20145.  
  20146.  The function is named _f_n_a_m_e; it shall be a name (see 3.1.5).  An           1
  20147.  implementation may allow other characters in a function name as an         1
  20148.  extension.  The implementation shall maintain separate namespaces for      1
  20149.  functions and variables.
  20150.  
  20151.  The argument _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d represents a compound command, as described
  20152.  in 3.9.4.
  20153.  
  20154.  When the function is declared, none of the expansions in 3.6 shall be
  20155.  performed on the text in _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d or _i_o-_r_e_d_i_r_e_c_t; all expansions
  20156.  shall be performed as normal each time the function is called.
  20157.  Similarly, the optional _i_o-_r_e_d_i_r_e_c_t redirections and any variable
  20158.  assignments within _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d shall be performed during the
  20159.  execution of the function itself, not the function definition.  See 3.8.1
  20160.  for the consequences of failures of these operations on interactive and
  20161.  noninteractive shells.
  20162.  
  20163.  When a function is executed, it shall have the syntax-error and
  20164.  variable-assignment properties described for special built-in utilities,
  20165.  in the enumerated list at the beginning of 3.14.
  20166.  
  20167.  The _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d shall be executed whenever the function name is
  20168.  specified as the name of a simple command (see 3.9.1.1).  The operands to
  20169.  the command temporarily shall become the positional parameters during the
  20170.  execution of the _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d; the special parameter # shall also be
  20171.  changed to reflect the number of operands.  The special parameter 0 shall
  20172.  be unchanged.  When the function completes, the values of the positional
  20173.  parameters and the special parameter # shall be restored to the values
  20174.  they had before the function was executed.  If the special built-in
  20175.  return is executed in the _c_o_m_p_o_u_n_d-_c_o_m_m_a_n_d, the function shall complete
  20176.  and execution shall resume with the next command after the function call.
  20177.  
  20178.  _E_x_i_t__S_t_a_t_u_s
  20179.  
  20180.  The exit status of a function definition shall be zero if the function
  20181.  was declared successfully; otherwise, it shall be greater than zero.  The
  20182.  exit status of a function invocation shall be the exit status of the last
  20183.  command executed by the function.
  20184.  
  20185.  
  20186.  
  20187.                Copyright c 1991 IEEE.  All rights reserved.
  20188.       This is an unapproved IEEE Standards Draft, subject to change.
  20189.  
  20190.  
  20191.  
  20192.  
  20193.  
  20194.  276                                              3 Shell Command Language
  20195.  
  20196.  
  20197.  
  20198.  
  20199.  
  20200.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20201.  
  20202.  BEGIN_RATIONALE
  20203.  
  20204.  
  20205.  3.9.5.1  Function Definition Command Rationale (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  20206.           _p_a_r_t _o_f _P_1_0_0_3._2)
  20207.  
  20208.  The description of functions in Draft 8 was based on the notion that
  20209.  functions should behave like miniature shell scripts; that is, except for
  20210.  sharing variables, most elements of an execution environment should
  20211.  behave as if it were a new execution environment, and changes to these
  20212.  should be local to the function.  For example, traps and options should
  20213.  be reset on entry to the function, and any changes to them don't affect
  20214.  the traps or options of the caller.  There were numerous objections to
  20215.  this basic idea, and the opponents asserted that functions were intended
  20216.  to be a convenient mechanism for grouping commonly executed commands that
  20217.  were to be executed in the current execution environment, similar to the
  20218.  execution of the dot special built-in.
  20219.  
  20220.  Opponents also pointed out that the functions described in Draft 8 did
  20221.  not scope everything a new shell script would anyway, such as the current
  20222.  working directory, or umask, but instead picked a few select properties.
  20223.  The basic argument was that if one wanted scoping of the execution
  20224.  environment, the mechanism already exists: put the commands in a new
  20225.  shell script and call it.  All traditional shells that implemented
  20226.  functions, other than the KornShell, have implemented functions that
  20227.  operate in the current execution environment.  Because of this, Draft 9
  20228.  removed any local scoping of traps or options.  Local variables within a
  20229.  function were considered and included in Draft 9 (controlled by the
  20230.  special built-in local), but were removed because they do not fit the
  20231.  simple model developed for the scoping of functions and there was some
  20232.  opposition to adding yet another new special built-in from outside
  20233.  existing practice.  Implementations should reserve the identifier local
  20234.  (as well as typeset, as used in the KornShell) in case this local
  20235.  variable mechanism is adopted in a future version of POSIX.2.
  20236.  
  20237.  A separate issue from the execution environment of a function is the
  20238.  availability of that function to child shells.  A few objectors,
  20239.  including the author of the original Version 7 UNIX system shell,
  20240.  maintained that just as a variable can be shared with child shells by
  20241.  exporting it, so should a function--and so this capability has been added
  20242.  to the standard.  In previous drafts, the export command therefore had a
  20243.  -f flag for exporting functions.  Functions that were exported were to be
  20244.  put into the environment as _n_a_m_e()=_v_a_l_u_e pairs, and upon invocation, the
  20245.  shell would scan the environment for these, and automatically define
  20246.  these functions.  This facility received a lot of balloting opposition
  20247.  and was removed from Draft 11.  Some of the arguments against exportable
  20248.  functions were:
  20249.  
  20250.  
  20251.  
  20252.  
  20253.                Copyright c 1991 IEEE.  All rights reserved.
  20254.       This is an unapproved IEEE Standards Draft, subject to change.
  20255.  
  20256.  
  20257.  
  20258.  
  20259.  
  20260.  3.9 Shell Commands                                                    277
  20261.  
  20262.  
  20263.  
  20264.  
  20265.  
  20266.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20267.  
  20268.      - There was little existing practice.  The Ninth Edition shell
  20269.        provided them, but there was controversy over how well it worked.
  20270.  
  20271.      - There are numerous security problems associated with functions
  20272.        appearing in a script's environment and overriding standard
  20273.        utilities or the application's own utilities.
  20274.  
  20275.      - There was controversy over requiring make to import functions,
  20276.        where it has historically used an _e_x_e_c function for many of its
  20277.        command line executions.
  20278.  
  20279.      - Functions can be big and the environment is of a limited size.
  20280.        (The counter-argument was that functions are no different than
  20281.        variables in terms of size: there can be big ones, and there can be
  20282.        small ones--and just as one does not export huge variables, one
  20283.        does not export huge functions.  However, this insight might be
  20284.        lost on the average shell-function writer, who typically writes
  20285.        much larger functions than variables.)
  20286.  
  20287.  As far as can be determined, the functions in POSIX.2 match those in
  20288.  System V.  The KornShell has two methods of defining functions:
  20289.  
  20290.        function _f_n_a_m_e { _c_o_m_p_o_u_n_d-_l_i_s_t }
  20291.  
  20292.  and
  20293.  
  20294.        _f_n_a_m_e() { _c_o_m_p_o_u_n_d-_l_i_s_t }
  20295.  
  20296.  The latter uses the same definition as POSIX.2, but differs in semantics,
  20297.  as described previously.  A future edition of the KornShell is planned to
  20298.  align the latter syntax with POSIX and keep the former as-is.
  20299.  
  20300.  The name space for functions is limited to that of a _n_a_m_e because of       1
  20301.  historical practice.  Complications in defining the syntactic rules for    1
  20302.  the function definition command and in dealing with known extensions such  1
  20303.  as the KornShell's @() prevented the name space from being widened to a    1
  20304.  _w_o_r_d, as requested by some balloters.  Using functions to support          1
  20305.  synonyms such as the C-shell's !! and % is thus disallowed to portable     1
  20306.  applications, but acceptable as an extension.  For interactive users, the  1
  20307.  aliasing facilities in the UPE should be adequate for this purpose.  It    1
  20308.  is recognized that the name space for utilities in the file system is      1
  20309.  wider than that currently supported for functions, if the portable         1
  20310.  filename character set guidelines are ignored, but it did not seem useful  1
  20311.  to mandate extensions in systems for so little benefit to portable         1
  20312.  applications.                                                              1
  20313.  
  20314.  The () in the function definition command consists of two operators.
  20315.  Therefore, intermixing <blank>_s with the _f_n_a_m_e, (, and ) is allowed, but
  20316.  unnecessary.
  20317.  
  20318.  
  20319.                Copyright c 1991 IEEE.  All rights reserved.
  20320.       This is an unapproved IEEE Standards Draft, subject to change.
  20321.  
  20322.  
  20323.  
  20324.  
  20325.  
  20326.  278                                              3 Shell Command Language
  20327.  
  20328.  
  20329.  
  20330.  
  20331.  
  20332.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20333.  
  20334.  An example of how a function definition can be used wherever a simple
  20335.  command is allowed:
  20336.  
  20337.        # If variable i is equal to "yes",
  20338.        # define function foo to be ls -l
  20339.        #
  20340.        [ X$i = Xyes ] && foo() {
  20341.                ls -l
  20342.        }
  20343.  
  20344.  END_RATIONALE
  20345.  
  20346.  
  20347.  
  20348.  3.10  Shell Grammar
  20349.  
  20350.  The following grammar describes the Shell Command Language.  Any
  20351.  discrepancies found between this grammar and the preceding description
  20352.  shall be resolved in favor of this clause.
  20353.  
  20354.  
  20355.  3.10.1  Shell Grammar Lexical Conventions
  20356.  
  20357.  The input language to the shell must be first recognized at the character
  20358.  level.  The resulting tokens shall be classified by their immediate
  20359.  context according to the following rules (applied in order).  These rules
  20360.  are used to determine what a ``token'' that is subject to parsing at the
  20361.  token level is.  The rules for token recognition in 3.3 shall apply.
  20362.  
  20363.      (1)  A <newline> shall be returned as the token identifier NEWLINE.
  20364.  
  20365.      (2)  If the token is an operator, the token identifier for that
  20366.           operator shall result.
  20367.  
  20368.      (3)  If the string consists solely of digits and the delimiter
  20369.           character is one of < or >, the token identifier IO_NUMBER shall
  20370.           be returned.
  20371.  
  20372.      (4)  Otherwise, the token identifier TOKEN shall result.
  20373.  
  20374.  Further distinction on TOKEN is context-dependent.  It may be that the
  20375.  same TOKEN yields WORD, a NAME, an ASSIGNMENT, or one of the reserved
  20376.  words below, dependent upon the context.  Some of the productions in the
  20377.  grammar below are annotated with a rule number from the following list.
  20378.  When a TOKEN is seen where one of those annotated productions could be
  20379.  used to reduce the symbol, the applicable rule shall be applied to
  20380.  convert the token identifier type of the TOKEN to a token identifier
  20381.  acceptable at that point in the grammar.  The reduction shall then
  20382.  proceed based upon the token identifier type yielded by the rule applied.
  20383.  When more than one rule applies, the highest numbered rule shall apply
  20384.  
  20385.                Copyright c 1991 IEEE.  All rights reserved.
  20386.       This is an unapproved IEEE Standards Draft, subject to change.
  20387.  
  20388.  
  20389.  
  20390.  
  20391.  
  20392.  3.10 Shell Grammar                                                    279
  20393.  
  20394.  
  20395.  
  20396.  
  20397.  
  20398.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20399.  
  20400.  (which in turn may refer to another rule).  [Note that except in rule
  20401.  (7), the presence of an = in the token has no effect.]
  20402.  
  20403.  The WORD tokens shall have the word expansion rules applied to them
  20404.  immediately before the associated command is executed, not at the time
  20405.  the command is parsed.
  20406.  
  20407.  
  20408.  3.10.2  Shell Grammar Rules
  20409.  
  20410.      (1)  [Command Name]
  20411.           When the TOKEN is exactly a reserved word, the token identifier
  20412.           for that reserved word shall result.  Otherwise, the token WORD
  20413.           shall be returned.  Also, if the parser is in any state where     1
  20414.           only a reserved word could be the next correct token, proceed as  1
  20415.           above.                                                            1
  20416.  
  20417.           NOTE:  Because at this point quote marks are retained in the
  20418.           token, quoted strings cannot be recognized as reserved words.
  20419.           This rule also implies that reserved words will not be
  20420.           recognized except in certain positions in the input, such as
  20421.           after a <newline> or semicolon; the grammar presumes that if the
  20422.           reserved word is intended, it will be properly delimited by the
  20423.           user, and does not attempt to reflect that requirement directly.
  20424.           Also note that line joining is done before tokenization, as
  20425.           described in 3.2.1, so escaped newlines are already removed at
  20426.           this point.
  20427.  
  20428.           NOTE:  Rule (1) is not directly referenced in the grammar, but    1
  20429.           is referred to by other rules, or applies globally.               1
  20430.  
  20431.      (2)  [Redirection to/from filename]
  20432.           The expansions specified in 3.7 shall occur.  As specified
  20433.           there, exactly one field can result (or the result is             1
  20434.           unspecified), and there are additional requirements on pathname
  20435.           expansion.
  20436.  
  20437.      (3)  [Redirection from here-document]
  20438.           Quote removal [3.7.4].  shall be applied to the word to           1
  20439.           determine the delimiter that will be used to find the end of the  1
  20440.           here-document that begins after the next <newline>.               1
  20441.  
  20442.      (4)  [Case statement termination]
  20443.           When the TOKEN is exactly the reserved word Esac, the token
  20444.           identifier for Esac shall result.  Otherwise, the token WORD
  20445.           shall be returned.
  20446.  
  20447.      (5)  [NAME in for]
  20448.           When the TOKEN meets the requirements for a name [3.1.5], the
  20449.  
  20450.  
  20451.                Copyright c 1991 IEEE.  All rights reserved.
  20452.       This is an unapproved IEEE Standards Draft, subject to change.
  20453.  
  20454.  
  20455.  
  20456.  
  20457.  
  20458.  280                                              3 Shell Command Language
  20459.  
  20460.  
  20461.  
  20462.  
  20463.  
  20464.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20465.  
  20466.           token identifier NAME shall result.  Otherwise, the token WORD
  20467.           shall be returned.
  20468.  
  20469.      (6)  [Third word of for and case]
  20470.           When the TOKEN is exactly the reserved word In, the token
  20471.           identifier for In shall result.  Otherwise, the token WORD shall
  20472.           be returned.
  20473.  
  20474.      (7)  [Assignment preceding command name]                               1
  20475.  
  20476.            (a)  [When the first word]
  20477.                 If the TOKEN does not contain the character =, rule (1)
  20478.                 shall be applied.  Otherwise, apply (7)(b).
  20479.  
  20480.            (b)  [Not the first word]
  20481.                 If the TOKEN contains the equals-sign character:
  20482.  
  20483.                  - If it begins with =, the token WORD shall be returned.
  20484.  
  20485.                  - If all the characters preceding = form a valid name
  20486.                    [3.1.5], the token ASSIGNMENT_WORD shall be returned.
  20487.                    (Quoted characters cannot participate in forming a
  20488.                    valid name.)
  20489.  
  20490.                  - Otherwise, it is unspecified whether it is
  20491.                    ASSIGNMENT_WORD or WORD that is returned.
  20492.  
  20493.           Assignment to the NAME shall occur as specified in 3.9.1.
  20494.  
  20495.      (8)  [NAME in function]
  20496.           When the TOKEN is exactly a reserved word, the token identifier
  20497.           for that reserved word shall result.  Otherwise, when the TOKEN
  20498.           meets the requirements for a name [3.1.5], the token identifier
  20499.           NAME shall result.  Otherwise, rule (7) shall apply.
  20500.  
  20501.      (9)  [Body of function]
  20502.           Word expansion and assignment shall never occur, even when
  20503.           required by the rules above, when this rule is being parsed.
  20504.           Each TOKEN that might either be expanded or have assignment
  20505.           applied to it shall instead be returned as a single WORD
  20506.           consisting only of characters that are exactly the token
  20507.           described in 3.3.
  20508.  
  20509.  /*       -------------------------------------------------------
  20510.           The grammar symbols
  20511.           ------------------------------------------------------- */
  20512.  
  20513.  
  20514.  
  20515.  
  20516.  
  20517.                Copyright c 1991 IEEE.  All rights reserved.
  20518.       This is an unapproved IEEE Standards Draft, subject to change.
  20519.  
  20520.  
  20521.  
  20522.  
  20523.  
  20524.  3.10 Shell Grammar                                                    281
  20525.  
  20526.  
  20527.  
  20528.  
  20529.  
  20530.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20531.  
  20532.  %token   WORD
  20533.  %token   ASSIGNMENT_WORD
  20534.  %token   NAME
  20535.  %token   NEWLINE
  20536.  %token   IO_NUMBER
  20537.  
  20538.  /*       The following are the operators mentioned above.        */
  20539.  
  20540.  %token   AND_IF OR_IF DSEMI
  20541.  /*       '&&'   '||'  ';;'                                        */
  20542.  
  20543.  %token   DLESS DGREAT LESSAND GREATAND LESSGREAT DLESSDASH
  20544.  /*       '<<'  '>>'   '<&'    '>&'     '<>'     '<<-'            */
  20545.  
  20546.  %token   CLOBBER
  20547.  /*       '>|'                                                    */
  20548.  
  20549.  /*       The following are the reserved words                    */
  20550.  
  20551.  %token    If   Then   Else   Elif   Fi   Do   Done
  20552.  /*       'if' 'then' 'else' 'elif' 'fi' 'do' 'done'              */
  20553.  
  20554.  %token    Case   Esac   While   Until   For
  20555.  /*       'case' 'esac' 'while' 'until' 'for'                     */
  20556.  
  20557.  /*       These are reserved words, not operator tokens, and are
  20558.           recognized when reserved words are recognized.          */
  20559.  
  20560.  %token   Lbrace Rbrace Bang
  20561.  /*        '{'    '}'    '!'                                      */
  20562.  
  20563.  %token   In
  20564.  /*       'in'                                                    */
  20565.  
  20566.  /*       -------------------------------------------------------
  20567.           The Grammar
  20568.           ------------------------------------------------------- */
  20569.  
  20570.  %start   complete_command
  20571.  
  20572.  %%
  20573.  
  20574.  complete_command    : list separator
  20575.                      | list                                                 1
  20576.                      ;
  20577.  
  20578.  list                : list separator_op and_or
  20579.  
  20580.  
  20581.  
  20582.  
  20583.                Copyright c 1991 IEEE.  All rights reserved.
  20584.       This is an unapproved IEEE Standards Draft, subject to change.
  20585.  
  20586.  
  20587.  
  20588.  
  20589.  
  20590.  282                                              3 Shell Command Language
  20591.  
  20592.  
  20593.  
  20594.  
  20595.  
  20596.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20597.  
  20598.                      |                   and_or
  20599.                      ;
  20600.  
  20601.  and_or              :                         pipeline
  20602.                      | and_or AND_IF linebreak pipeline
  20603.                      | and_or OR_IF  linebreak pipeline
  20604.                      ;
  20605.  
  20606.  pipeline            :      pipe_sequence
  20607.                      | Bang pipe_sequence
  20608.                      ;
  20609.  
  20610.  pipe_sequence       :                            command
  20611.                      | pipe_sequence '|' linebreak command
  20612.                      ;
  20613.  
  20614.  command             : simple_command
  20615.                      | compound_command
  20616.                      | compound_command redirect_list
  20617.                      | function_definition
  20618.                      ;
  20619.  
  20620.  compound_command    : brace_group
  20621.                      | subshell
  20622.                      | for_clause
  20623.                      | case_clause
  20624.                      | if_clause
  20625.                      | while_clause
  20626.                      | until_clause
  20627.                      ;
  20628.  
  20629.  subshell            : '(' compound_list ')'
  20630.                      ;
  20631.  
  20632.  compound_list       :              term
  20633.                      | newline_list term
  20634.                      |              term separator
  20635.                      | newline_list term separator
  20636.                      ;
  20637.  
  20638.  term                : term separator and_or
  20639.                      |                and_or
  20640.                      ;
  20641.  
  20642.  for_clause          : For name                            do_group
  20643.                      | For name In wordlist sequential_sep do_group
  20644.                      ;
  20645.  
  20646.  
  20647.  
  20648.  
  20649.                Copyright c 1991 IEEE.  All rights reserved.
  20650.       This is an unapproved IEEE Standards Draft, subject to change.
  20651.  
  20652.  
  20653.  
  20654.  
  20655.  
  20656.  3.10 Shell Grammar                                                    283
  20657.  
  20658.  
  20659.  
  20660.  
  20661.  
  20662.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20663.  
  20664.  name                : NAME                     /* Apply rule (5) */        2
  20665.                      ;
  20666.  
  20667.  in                  : In                       /* Apply rule (6) */
  20668.                      ;
  20669.  
  20670.  wordlist            : wordlist WORD
  20671.                      |          WORD
  20672.                      ;
  20673.  
  20674.  case_clause         : Case WORD In linebreak case_list Esac
  20675.                      | Case WORD In linebreak           Esac
  20676.                      ;
  20677.  
  20678.  case_list           : case_list case_item
  20679.                      |           case_item
  20680.                      ;
  20681.  
  20682.  case_item           :     pattern ')' linebreak     DSEMI linebreak
  20683.                      |     pattern ')' compound_list DSEMI linebreak
  20684.                      | '(' pattern ')' linebreak     DSEMI linebreak        2
  20685.                      | '(' pattern ')' compound_list DSEMI linebreak        2
  20686.                      ;
  20687.  
  20688.  pattern             :            WORD          /* Apply rule (4) */
  20689.                      | pattern '|' WORD         /* Do not apply rule (4) */ 1
  20690.                      ;
  20691.  
  20692.  if_clause           : If compound_list Then compound_list else_part Fi
  20693.                      | If compound_list Then compound_list           Fi
  20694.                      ;
  20695.  
  20696.  else_part           : Elif compound_list Then else_part
  20697.                      | Else compound_list
  20698.                      ;
  20699.  
  20700.  while_clause        : While compound_list do_group
  20701.                      ;
  20702.  
  20703.  until_clause        : Until compound_list do_group
  20704.                      ;
  20705.  
  20706.  function_definition : fname '(' ')' linebreak function_body
  20707.                      ;
  20708.  
  20709.  function_body       : compound_command                /* Apply rule (9) */
  20710.                      | compound_command redirect_list  /* Apply rule (9) */
  20711.  
  20712.  
  20713.  
  20714.  
  20715.                Copyright c 1991 IEEE.  All rights reserved.
  20716.       This is an unapproved IEEE Standards Draft, subject to change.
  20717.  
  20718.  
  20719.  
  20720.  
  20721.  
  20722.  284                                              3 Shell Command Language
  20723.  
  20724.  
  20725.  
  20726.  
  20727.  
  20728.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20729.  
  20730.                      ;
  20731.  
  20732.  fname               : NAME                            /* Apply rule (8) */ 2
  20733.                      ;
  20734.  
  20735.  brace_group         : Lbrace compound_list Rbrace
  20736.                      ;
  20737.  
  20738.  do_group            : Do compound_list Done
  20739.                      ;
  20740.  
  20741.  simple_command      : cmd_prefix cmd_word cmd_suffix
  20742.                      | cmd_prefix cmd_word
  20743.                      | cmd_prefix
  20744.                      | cmd_name cmd_suffix
  20745.                      | cmd_name
  20746.                      ;
  20747.  
  20748.  cmd_name            : WORD                   /* Apply rule (7)(a) */
  20749.                      ;
  20750.  
  20751.  cmd_word            : WORD                   /* Apply rule (7)(b) */
  20752.                      ;
  20753.  
  20754.  cmd_prefix          :            io_redirect
  20755.                      | cmd_prefix io_redirect
  20756.                      |            ASSIGNMENT_WORD
  20757.                      | cmd_prefix ASSIGNMENT_WORD
  20758.                      ;
  20759.  
  20760.  cmd_suffix          :            io_redirect
  20761.                      | cmd_suffix io_redirect
  20762.                      |            WORD
  20763.                      | cmd_suffix WORD
  20764.                      ;
  20765.  
  20766.  
  20767.  redirect_list       :               io_redirect
  20768.                      | redirect_list io_redirect
  20769.                      ;
  20770.  
  20771.  io_redirect         :           io_file
  20772.                      | IO_NUMBER io_file
  20773.                      |           io_here
  20774.                      | IO_NUMBER io_here
  20775.                      ;
  20776.  
  20777.  
  20778.  
  20779.  
  20780.  
  20781.                Copyright c 1991 IEEE.  All rights reserved.
  20782.       This is an unapproved IEEE Standards Draft, subject to change.
  20783.  
  20784.  
  20785.  
  20786.  
  20787.  
  20788.  3.10 Shell Grammar                                                    285
  20789.  
  20790.  
  20791.  
  20792.  
  20793.  
  20794.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20795.  
  20796.  io_file             : '<'       filename
  20797.                      | LESSAND   filename
  20798.                      | '>'       filename
  20799.                      | GREATAND  filename
  20800.                      | DGREAT    filename
  20801.                      | LESSGREAT filename
  20802.                      | CLOBBER   filename
  20803.                      ;
  20804.  
  20805.  filename            : WORD                      /* Apply rule (2) */
  20806.                      ;
  20807.  
  20808.  io_here             : DLESS     here_end
  20809.                      | DLESSDASH here_end
  20810.                      ;
  20811.  
  20812.  here_end            : WORD                      /* Apply rule (3) */
  20813.                      ;
  20814.  
  20815.  newline_list        :              NEWLINE
  20816.                      | newline_list NEWLINE
  20817.                      ;
  20818.  
  20819.  linebreak           : newline_list
  20820.                      | /* empty */
  20821.                      ;
  20822.  
  20823.  separator_op        : '&'
  20824.                      | ';'
  20825.                      ;
  20826.  
  20827.  separator           : separator_op linebreak
  20828.                      | newline_list
  20829.                      ;
  20830.  
  20831.  sequential_sep      : ';' linebreak
  20832.                      | newline_list
  20833.                      ;
  20834.  
  20835.  BEGIN_RATIONALE
  20836.  
  20837.  
  20838.  3.10.3  Shell Grammar Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f
  20839.          _P_1_0_0_3._2)
  20840.  
  20841.  There are several subtle aspects of this grammar where conventional usage
  20842.  implies rules about the grammar that in fact are not true.
  20843.  
  20844.  
  20845.  
  20846.  
  20847.                Copyright c 1991 IEEE.  All rights reserved.
  20848.       This is an unapproved IEEE Standards Draft, subject to change.
  20849.  
  20850.  
  20851.  
  20852.  
  20853.  
  20854.  286                                              3 Shell Command Language
  20855.  
  20856.  
  20857.  
  20858.  
  20859.  
  20860.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20861.  
  20862.  For compound_list, only the forms that end in a separator allow a
  20863.  reserved word to be recognized, so usually only a separator can be used    1
  20864.  where a compound list precedes a reserved word (such as Then, Else, Do,
  20865.  and Rbrace.  Explicitly requiring a separator would disallow such valid
  20866.  (if rare) statements as:
  20867.  
  20868.        if (false) then (echo x) else (echo y) fi
  20869.  
  20870.  See the NOTE under special grammar rule (1).
  20871.  
  20872.  Concerning the third sentence of rule (1) (``Also, if the parser ...''):   1
  20873.  
  20874.      - This sentence applies rather narrowly:  when a compound list is      1
  20875.        terminated by some clear delimiter (such as the closing fi of an     1
  20876.        inner if_clause) then it would apply; where the compound list might  1
  20877.        continue (as in after a ;), rule (7a) [and consequently the first    1
  20878.        sentence of rule (1)] would apply.  In many instances the two        1
  20879.        conditions are identical, but this part of rule (1) does not give    1
  20880.        license to treating a WORD as a reserved words unless it is in a     1
  20881.        place where a reserved word must appear.                             1
  20882.  
  20883.      - The statement is equivalent to requiring that when the LR(1)         2
  20884.        lookahead set contains exactly a reserved word, it must be           2
  20885.        recognized if it is present.  (Here ``LR(1)'' refers to the          2
  20886.        theoretical concepts, not to any real parser generator.)             2
  20887.  
  20888.        For example, in the construct below, and when the parser is at the   2
  20889.        point marked with ^, the only next legal token is then (this         2
  20890.        follows directly from the grammar rules).                            2
  20891.  
  20892.              if if....fi then ....  fi                                      2
  20893.                         ^                                                   2
  20894.  
  20895.        At that point, the then must be recognized as a reserved word.       2
  20896.  
  20897.        (Depending on the actual parser generator actually used, ``extra''   2
  20898.        reserved words may be in some lookahead sets.  It does not really    2
  20899.        matter if they are recognized, or even if any possible reserved      2
  20900.        word is recognized in that state, because if it is recognized and    2
  20901.        is not in the (theoretical) LR(1) lookahead set, an error will       2
  20902.        ultimately be detected.  In the example above, if some other         2
  20903.        reserved word (e.g., while) is also recognized, an error will occur  2
  20904.        later.                                                               2
  20905.  
  20906.        This is approximately equivalent to saying that reserved words are   2
  20907.        recognized after other reserved words (because it is after a         2
  20908.        reserved word that this condition will occur), but avoids the        2
  20909.        ``except for...'' list that would be required for case, for, etc.    2
  20910.        (Reserved words are of course recognized anywhere a simple_command   2
  20911.  
  20912.  
  20913.                Copyright c 1991 IEEE.  All rights reserved.
  20914.       This is an unapproved IEEE Standards Draft, subject to change.
  20915.  
  20916.  
  20917.  
  20918.  
  20919.  
  20920.  3.10 Shell Grammar                                                    287
  20921.  
  20922.  
  20923.  
  20924.  
  20925.  
  20926.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  20927.  
  20928.        can appear, as well.  Other rules take care of the special cases of  2
  20929.        nonrecognition, such as rule (4) for case statements.)               2
  20930.  
  20931.  Note that the body of here-documents are handled by Token Recognition
  20932.  (see 3.3) and do not appear in the grammar directly.  (However, the
  20933.  here-document I/O redirection operator is handled as part of the
  20934.  grammar.)
  20935.  
  20936.  The start symbol of the grammar (complete_command) represents either
  20937.  input from the command line or a shell script.  It is repeatedly applied
  20938.  by the interpreter to its input, and represents a single ``chunk'' of
  20939.  that input as seen by the interpreter.                                     1
  20940.  
  20941.  The processing of here-documents is handled as part of token recognition
  20942.  (see 3.3) rather than as part of the grammar.
  20943.  
  20944.  END_RATIONALE
  20945.  
  20946.  
  20947.  
  20948.  3.11  Signals and Error Handling
  20949.  
  20950.  When a command is in an asynchronous list, the shell shall prevent
  20951.  SIGQUIT and SIGINT signals from the keyboard from interrupting the
  20952.  command.  Otherwise, signals shall have the values inherited by the shell
  20953.  from its parent (see also 3.14.13).
  20954.  
  20955.  When a signal for which a trap has been set is received while the shell    1
  20956.  is waiting for the completion of a utility executing a foreground          1
  20957.  command, the trap associated with that signal shall not be executed until  1
  20958.  after the foreground command has completed.  When the shell is waiting,    1
  20959.  by means of the wait utility, for asynchronous commands to complete, the   1
  20960.  reception of a signal for which a trap has been set shall cause the wait   1
  20961.  utility to return immediately with an exit status >128, immediately after  1
  20962.  which the trap associated with that signal shall be taken.                 1
  20963.  
  20964.  If multiple signals are pending for the shell for which there are
  20965.  associated trap actions (see 3.14.13), the order of execution of trap
  20966.  actions is unspecified.
  20967.  
  20968.  
  20969.  
  20970.  
  20971.  
  20972.  
  20973.  
  20974.  
  20975.  
  20976.  
  20977.  
  20978.  
  20979.                Copyright c 1991 IEEE.  All rights reserved.
  20980.       This is an unapproved IEEE Standards Draft, subject to change.
  20981.  
  20982.  
  20983.  
  20984.  
  20985.  
  20986.  288                                              3 Shell Command Language
  20987.  
  20988.  
  20989.  
  20990.  
  20991.  
  20992.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  20993.  
  20994.  3.12  Shell Execution Environment
  20995.  
  20996.  A shell execution environment consists of the following:
  20997.  
  20998.      - Open files inherited upon invocation of the shell, plus open files
  20999.        controlled by exec.
  21000.  
  21001.      - Working Directory as set by cd (see 4.5).
  21002.  
  21003.      - File Creation Mask set by umask (see 4.67).
  21004.  
  21005.      - Current traps set by trap (see 3.14.13).
  21006.  
  21007.      - Shell parameters that are set by variable assignment (see set in
  21008.        3.14.11) or from the POSIX.1 {8} environment inherited by the shell
  21009.        when it begins (see export in 3.14.8).
  21010.  
  21011.      - Shell functions (see 3.9.5.)
  21012.  
  21013.      - Options turned on at invocation or by set.
  21014.  
  21015.      - Process IDs of the last commands in asynchronous lists known to      1
  21016.        this shell environment; see 3.9.3.1.                                 1
  21017.  
  21018.  Utilities other than the special built-ins (see 3.14) shall be invoked in
  21019.  a separate environment that consists of the following.  The initial value
  21020.  of these objects shall be the same as that for the parent shell, except
  21021.  as noted below.
  21022.  
  21023.      - Open files inherited on invocation of the shell, open files
  21024.        controlled by the exec special built-in (see 3.14.6), plus any
  21025.        modifications and additions specified by any redirections to the
  21026.        utility.
  21027.  
  21028.      - Current working directory.
  21029.  
  21030.      - File creation mask.
  21031.  
  21032.      - If the utility is a shell script, traps caught by the shell shall
  21033.        be set to the default values and traps ignored by the shell shall
  21034.        be set to be ignored by the utility.  If the utility is not a shell
  21035.        script, the trap actions (default or ignore) shall be mapped into
  21036.        the appropriate signal handling actions for the utility.
  21037.  
  21038.      - Variables with the export attribute, along with those explicitly
  21039.        exported for the duration of the command, shall be passed to the
  21040.        utility as POSIX.1 {8} environment variables.
  21041.  
  21042.  
  21043.  
  21044.  
  21045.                Copyright c 1991 IEEE.  All rights reserved.
  21046.       This is an unapproved IEEE Standards Draft, subject to change.
  21047.  
  21048.  
  21049.  
  21050.  
  21051.  
  21052.  3.12 Shell Execution Environment                                      289
  21053.  
  21054.  
  21055.  
  21056.  
  21057.  
  21058.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21059.  
  21060.  The environment of the shell process shall not be changed by the utility
  21061.  unless explicitly specified by the utility description (for example, cd
  21062.  and umask).
  21063.  
  21064.  A subshell environment shall be created as a duplicate of the shell
  21065.  environment, except that signal traps set by that shell environment shall  1
  21066.  be set to the default values.  Changes made to the subshell environment    1
  21067.  shall not affect the shell environment.  Command substitution, commands
  21068.  that are grouped with parentheses, and asynchronous lists shall be
  21069.  executed in a subshell environment.  Additionally, each command of a
  21070.  multicommand pipeline is in a subshell environment; as an extension,
  21071.  however, any or all commands in a pipeline may be executed in the current
  21072.  environment.  All other commands shall be executed in the current shell
  21073.  environment.
  21074.  
  21075.  BEGIN_RATIONALE
  21076.  
  21077.  
  21078.  3.12.0.1  Shell Execution Environment Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  21079.            _p_a_r_t _o_f _P_1_0_0_3._2)
  21080.  
  21081.  Some systems have implemented the last stage of a pipeline in the current
  21082.  environment so that commands such as
  21083.  
  21084.        _c_o_m_m_a_n_d | read foo
  21085.  
  21086.  set variable foo in the current environment.  It was decided to allow
  21087.  this extension, but not require it; therefore, a shell programmer should
  21088.  consider a pipeline to be in a subshell environment, but not depend on
  21089.  it.
  21090.  
  21091.  The previous description of execution environment failed to mention that
  21092.  each command in a multiple command pipeline could be in a subshell
  21093.  execution environment.  For compatibility with some existing shells, the
  21094.  wording was phrased to allow an implementation to place any or all
  21095.  commands of a pipeline in the current environment.  However, this means
  21096.  that a POSIX application must assume each command is in a subshell
  21097.  environment, but not depend on it.
  21098.  
  21099.  The wording about shell scripts is meant to convey the fact that
  21100.  describing ``trap actions'' can only be understood in the context of the
  21101.  shell command language.  Outside this context, such as in a C-language
  21102.  program, signals are the operative condition, not traps.
  21103.  
  21104.  END_RATIONALE
  21105.  
  21106.  
  21107.  
  21108.  
  21109.  
  21110.  
  21111.                Copyright c 1991 IEEE.  All rights reserved.
  21112.       This is an unapproved IEEE Standards Draft, subject to change.
  21113.  
  21114.  
  21115.  
  21116.  
  21117.  
  21118.  290                                              3 Shell Command Language
  21119.  
  21120.  
  21121.  
  21122.  
  21123.  
  21124.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21125.  
  21126.  3.13  Pattern Matching Notation
  21127.  
  21128.  The pattern matching notation described in this clause is used to specify
  21129.  patterns for matching strings in the shell.  Historically, pattern
  21130.  matching notation is related to, but slightly different from, the regular
  21131.  expression notation described in 2.8.  For this reason, the description
  21132.  of the rules for this pattern matching notation are based on the
  21133.  description of regular expression notation.
  21134.  
  21135.  BEGIN_RATIONALE
  21136.  
  21137.  
  21138.  3.13.0.1  Pattern Matching Notation Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a
  21139.            _p_a_r_t _o_f _P_1_0_0_3._2)
  21140.  
  21141.  Pattern matching is a simpler concept and has a simpler syntax than
  21142.  regular expressions, as the former is generally used for the manipulation
  21143.  of file names, which are relatively simple collections of characters,
  21144.  while the latter is generally used to manipulate arbitrary text strings
  21145.  of potentially greater complexity.  However, some of the basic concepts
  21146.  are the same, so this clause points liberally to the detailed
  21147.  descriptions in 2.8.
  21148.  
  21149.  END_RATIONALE
  21150.  
  21151.  
  21152.  3.13.1  Patterns Matching a Single Character
  21153.  
  21154.  The following _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r match a single
  21155.  character:  _o_r_d_i_n_a_r_y _c_h_a_r_a_c_t_e_r_s, _s_p_e_c_i_a_l _p_a_t_t_e_r_n _c_h_a_r_a_c_t_e_r_s, and _p_a_t_t_e_r_n
  21156.  _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n_s.  The pattern bracket expression also shall match a
  21157.  single collating element.
  21158.  
  21159.  An ordinary character is a pattern that shall match itself.  It can be
  21160.  any character in the supported character set except for NUL, those         1
  21161.  special shell characters in 3.2 that require quoting, and the following    1
  21162.  three special pattern characters.  Matching shall be based on the bit      1
  21163.  pattern used for encoding the character, not on the graphic                1
  21164.  representation of the character.  If any character (ordinary, shell        1
  21165.  special, or pattern special) is quoted, that pattern shall match the       1
  21166.  character itself.  The shell special characters always require quoting.    1
  21167.  
  21168.  When unquoted and outside a bracket expression, the following three        1
  21169.  characters shall have special meaning in the specification of patterns:    1
  21170.  
  21171.     ?     A question-mark is a pattern that shall match any character.
  21172.  
  21173.     *     An asterisk is a pattern that shall match multiple characters,
  21174.           as described in 3.13.2.
  21175.  
  21176.  
  21177.                Copyright c 1991 IEEE.  All rights reserved.
  21178.       This is an unapproved IEEE Standards Draft, subject to change.
  21179.  
  21180.  
  21181.  
  21182.  
  21183.  
  21184.  3.13 Pattern Matching Notation                                        291
  21185.  
  21186.  
  21187.  
  21188.  
  21189.  
  21190.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21191.  
  21192.     [     The open bracket shall introduce a pattern bracket expression.
  21193.  
  21194.  The description of basic regular expression bracket expressions in
  21195.  2.8.3.2 also shall apply to the pattern bracket expression, except that
  21196.  the exclamation-mark character (!) shall replace the circumflex character
  21197.  (^) in its role in a _n_o_n_m_a_t_c_h_i_n_g _l_i_s_t in the regular expression notation.
  21198.  A bracket expression starting with an unquoted circumflex character
  21199.  produces unspecified results.
  21200.  
  21201.  When pattern matching is used where shell quote removal is not performed   1
  21202.  [such as in the argument to the find -name primary when find is being      1
  21203.  called using an _e_x_e_c function, or in the _p_a_t_t_e_r_n argument to the           1
  21204.  _f_n_m_a_t_c_h() function], special characters can be escaped to remove their     1
  21205.  special meaning by preceding them with a <backslash>.  This escaping       1
  21206.  <backslash> shall be discarded.  The sequence \\ shall represent one       1
  21207.  literal backslash.  All of the requirements and effects of quoting on      1
  21208.  ordinary, shell special, and special pattern characters shall apply to     1
  21209.  escaping in this context.                                                  1
  21210.  
  21211.  BEGIN_RATIONALE                                                            1
  21212.  
  21213.  
  21214.  3.13.1.1  Patterns Matching a Single Character Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e
  21215.            _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21216.  
  21217.  Both ``quoting'' and ``escaping'' are described here because pattern       1
  21218.  matching must work in three separate circumstances:                        1
  21219.  
  21220.      - Calling directly upon the shell, such as in pathname expansion or    1
  21221.        in a case statement.  All of the following will match the string or  1
  21222.        file abc:  abc, "abc", a"b"c, a\bc, a[b]c, a["b"]c, a[\b]c, a?c,     1
  21223.        a*c.  The following will not:  "a?c", a\*c, a\[b]c, a["\b"]c.        1
  21224.  
  21225.      - Calling a utility or function without going through a shell, as      1
  21226.        described for find and _f_n_m_a_t_c_h().                                    1
  21227.  
  21228.      - Calling utilities such as find or pax through the shell command      1
  21229.        line.  (Although find and pax are the only instances of this in the  1
  21230.        standard utilities, describing it globally here is useful for        1
  21231.        future utilities that may use pattern matching internally.)  In      1
  21232.        this case, shell quote removal is performed before the utility sees  1
  21233.        the argument.  For example, in                                       1
  21234.  
  21235.              find /bin -name "e\c[\h]o" -print                              1
  21236.  
  21237.        after quote removal, the backslashes are presented to find and it    1
  21238.        treats them as escape characters.  Both precede ordinary             1
  21239.        characters, so the c and h represent themselves and echo would be    1
  21240.        found on many historical systems (that have it in /bin).  To find a  1
  21241.        filename that contained shell special characters or pattern          1
  21242.  
  21243.                Copyright c 1991 IEEE.  All rights reserved.
  21244.       This is an unapproved IEEE Standards Draft, subject to change.
  21245.  
  21246.  
  21247.  
  21248.  
  21249.  
  21250.  292                                              3 Shell Command Language
  21251.  
  21252.  
  21253.  
  21254.  
  21255.  
  21256.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21257.  
  21258.        characters, both quoting and escaping are required, such as          1
  21259.  
  21260.              pax -r ... "*a\(\?"                                            1
  21261.  
  21262.        to extract a filename ending with ``a(?''.                           1
  21263.  
  21264.  Conforming applications are required to quote or escape the shell special  1
  21265.  characters (called ``metacharacters'' in some historical documentation).   1
  21266.  If used without this protection, syntax errors can result or               1
  21267.  implementation extensions can be triggered.  For example, the KornShell    1
  21268.  supports a series of extensions based on parentheses in patterns.          1
  21269.  
  21270.  The restriction on circumflex in a bracket expression is to allow
  21271.  implementations that support pattern matching using circumflex as the
  21272.  negation character in addition to the exclamation-mark.                    1
  21273.  
  21274.  END_RATIONALE                                                              1
  21275.  
  21276.  
  21277.  3.13.2  Patterns Matching Multiple Characters
  21278.  
  21279.  The following rules are used to construct _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _m_u_l_t_i_p_l_e
  21280.  _c_h_a_r_a_c_t_e_r_s from _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e _c_h_a_r_a_c_t_e_r:
  21281.  
  21282.      (1)  The asterisk (*) is a pattern that shall match any string,
  21283.           including the null string.
  21284.  
  21285.      (2)  The concatenation of _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e _c_h_a_r_a_c_t_e_r is a
  21286.           valid pattern that shall match the concatenation of the single
  21287.           characters or collating elements matched by each of the
  21288.           concatenated patterns.
  21289.  
  21290.      (3)  The concatenation of one or more _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e
  21291.           _c_h_a_r_a_c_t_e_r with one or more asterisks is a valid pattern.  In
  21292.           such patterns, each asterisk shall match a string of zero or
  21293.           more characters, matching the greatest possible number of
  21294.           characters that still allows the remainder of the pattern to
  21295.           match the string.
  21296.  
  21297.  BEGIN_RATIONALE
  21298.  
  21299.  
  21300.  3.13.2.1  Patterns Matching Multiple Characters Rationale. (_T_h_i_s
  21301.            _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21302.  
  21303.  Since each asterisk matches ``zero or more'' occurrences, the patterns
  21304.  a*b and a**b have identical functionality.
  21305.  
  21306.  
  21307.  
  21308.  
  21309.                Copyright c 1991 IEEE.  All rights reserved.
  21310.       This is an unapproved IEEE Standards Draft, subject to change.
  21311.  
  21312.  
  21313.  
  21314.  
  21315.  
  21316.  3.13 Pattern Matching Notation                                        293
  21317.  
  21318.  
  21319.  
  21320.  
  21321.  
  21322.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21323.  
  21324.  _E_x_a_m_p_l_e_s:
  21325.  
  21326.     a[bc]       matches the strings ab and ac.
  21327.  
  21328.     a*d         matches the strings ad, abd, and abcd, but not the string
  21329.                 abc.
  21330.  
  21331.     a*d*        matches the strings ad, abcd, abcdef, aaaad, and adddd;
  21332.  
  21333.     *a*d        matches the strings ad, abcd, efabcd, aaaad, and adddd.
  21334.  
  21335.  END_RATIONALE
  21336.  
  21337.  
  21338.  3.13.3  Patterns Used for Filename Expansion
  21339.  
  21340.  The rules described so far in 3.13.1 and 3.13.2 are qualified by the
  21341.  following rules that apply when pattern matching notation is used for
  21342.  filename expansion.
  21343.  
  21344.      (1)  The slash character in a pathname shall be explicitly matched by
  21345.           using one or more slashes in the pattern; it cannot be matched
  21346.           by the asterisk or question-mark special characters or by a
  21347.           bracket expression.  Slashes in the pattern are identified
  21348.           before bracket expressions; thus, a slash cannot be included in
  21349.           a pattern bracket expression used for filename expansion.
  21350.  
  21351.      (2)  If a filename begins with a period (.), the period shall be
  21352.           explicitly matched by using a period as the first character of
  21353.           the pattern or immediately following a slash character.  The
  21354.           leading period shall not be matched by:
  21355.  
  21356.            - The asterisk or question-mark special characters, or
  21357.  
  21358.            - A bracket expression containing a nonmatching list (such as
  21359.              [!a]), a range expression (such as [%-0]), or a character
  21360.              class expression (such as [[:punct:]]).
  21361.  
  21362.           It is unspecified whether an explicit period in a bracket
  21363.           expression matching list (such as [.abc]) can match a leading
  21364.           period in a filename.
  21365.  
  21366.      (3)  Specified patterns are matched against existing filenames and
  21367.           pathnames, as appropriate.  Each component that contains a        2
  21368.           pattern character requires read permission in the directory       2
  21369.           containing that component.  Any component that does not contain   2
  21370.           a pattern character requires search permission.  For example,     2
  21371.           given the pattern                                                 2
  21372.  
  21373.  
  21374.  
  21375.                Copyright c 1991 IEEE.  All rights reserved.
  21376.       This is an unapproved IEEE Standards Draft, subject to change.
  21377.  
  21378.  
  21379.  
  21380.  
  21381.  
  21382.  294                                              3 Shell Command Language
  21383.  
  21384.  
  21385.  
  21386.  
  21387.  
  21388.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21389.  
  21390.                 /foo/bar/x*/bam                                             2
  21391.  
  21392.           search permission is needed for directory /foo, search and read   2
  21393.           permissions are needed for directory bar, and search permission   2
  21394.           is needed for each x* directory.  If the pattern matches any      2
  21395.           existing filenames or pathnames, the pattern shall be replaced
  21396.           with those filenames and pathnames, sorted according to the
  21397.           collating sequence in effect in the current locale.  If the
  21398.           pattern contains an invalid bracket expression or does not match
  21399.           any existing filenames or pathnames, the pattern string shall be
  21400.           left unchanged.
  21401.  
  21402.  BEGIN_RATIONALE
  21403.  
  21404.  
  21405.  3.13.3.1  Patterns Used for File Name Expansion Rationale. (_T_h_i_s
  21406.            _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21407.  
  21408.  The caveat about a slash within a bracket expression is derived from
  21409.  historical practice.  The pattern a[b/c]d will not match such pathnames
  21410.  as abd or a/d.  It will only match a pathname of literally a[b/c]d.
  21411.  
  21412.  Filenames beginning with a period historically have been specially
  21413.  protected from view on UNIX systems.  A proposal to allow an explicit
  21414.  period in a bracket expression to match a leading period was considered;
  21415.  it is allowed as an implementation extension, but a conforming
  21416.  application cannot make use of it.  If this extension becomes popular in
  21417.  the future, it will be considered for a future version of POSIX.2.
  21418.  
  21419.  Historical systems have varied in their permissions requirements.  To      2
  21420.  match f*/bar has required read permissions on the f* directories in the    2
  21421.  System V shell, but this standard, the C-shell, and KornShell require      2
  21422.  only search permissions.                                                   2
  21423.  
  21424.  END_RATIONALE                                                              2
  21425.  
  21426.  
  21427.  3.14  Special Built-in Utilities
  21428.  
  21429.  The following _s_p_e_c_i_a_l _b_u_i_l_t-_i_n utilities shall be supported in the shell
  21430.  command language.  The output of each command, if any, shall be written
  21431.  to standard output, subject to the normal redirection and piping possible
  21432.  with all commands.
  21433.  
  21434.  The term _b_u_i_l_t-_i_n implies that the shell can execute the utility directly
  21435.  and does not need to search for it.  An implementation can choose to make
  21436.  any utility a built-in; however, the special built-in utilities described
  21437.  here differ from regular built-in utilities in two respects:
  21438.  
  21439.  
  21440.  
  21441.                Copyright c 1991 IEEE.  All rights reserved.
  21442.       This is an unapproved IEEE Standards Draft, subject to change.
  21443.  
  21444.  
  21445.  
  21446.  
  21447.  
  21448.  3.14 Special Built-in Utilities                                       295
  21449.  
  21450.  
  21451.  
  21452.  
  21453.  
  21454.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21455.  
  21456.      (1)  A syntax error in a special built-in utility may cause a shell
  21457.           executing that utility to abort, while a syntax error in a
  21458.           regular built-in utility shall not cause a shell executing that
  21459.           utility to abort.  (See 3.8.1 for the consequences of errors on
  21460.           interactive and noninteractive shells.)  If a special built-in
  21461.           utility encountering a syntax error does not abort the shell,
  21462.           its exit value shall be nonzero.
  21463.  
  21464.      (2)  Variable assignments specified with special built-in utilities
  21465.           shall remain in effect after the built-in completes; this shall   1
  21466.           not be the case with a regular built-in or other utility.         1
  21467.  
  21468.  As described in 2.3, the special built-in utilities in this clause need
  21469.  not be provided in a manner accessible via the POSIX.1 {8} _e_x_e_c family of
  21470.  functions.
  21471.  
  21472.  Some of the special built-ins are described as conforming to the utility
  21473.  argument syntax guidelines in 2.10.2.  For those that are not, the
  21474.  requirement in 2.11.3 that "--" be recognized as a first argument to be
  21475.  discarded does not apply and a conforming application shall not use that
  21476.  argument.
  21477.  
  21478.  
  21479.  3.14.1  break - Exit from for, while, or until loop
  21480.  
  21481.        break [_n]
  21482.  
  21483.  Exit from the smallest enclosing for, while, or until loop, if any; or
  21484.  from the _nth enclosing loop if _n is specified.  The value of _n is an       1
  21485.  unsigned decimal integer _> 1.  The default is equivalent to _n=1.  If _n is
  21486.  greater than the number of enclosing loops, the last enclosing loop shall
  21487.  be exited from.  Execution continues with the command immediately
  21488.  following the loop.
  21489.  
  21490.  _E_x_i_t__S_t_a_t_u_s
  21491.  
  21492.      0    Successful completion.                                            2
  21493.  
  21494.     >0    The _n value was not an unsigned decimal integer _> 1.              2
  21495.  
  21496.  BEGIN_RATIONALE
  21497.  
  21498.  
  21499.  3.14.1.1  break Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21500.  
  21501.  Example:
  21502.  
  21503.  
  21504.  
  21505.  
  21506.  
  21507.                Copyright c 1991 IEEE.  All rights reserved.
  21508.       This is an unapproved IEEE Standards Draft, subject to change.
  21509.  
  21510.  
  21511.  
  21512.  
  21513.  
  21514.  296                                              3 Shell Command Language
  21515.  
  21516.  
  21517.  
  21518.  
  21519.  
  21520.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21521.  
  21522.        for i in *
  21523.        do
  21524.                if test -d "$i"
  21525.                then break
  21526.                fi
  21527.        done
  21528.  
  21529.  Consideration was given to expanding the syntax of the break and continue
  21530.  to refer to a label associated with the appropriate loop, as a preferable
  21531.  alternative to the [_n] method.  This new method was proposed late in the
  21532.  development of the standard and adequate consensus could not be formed to
  21533.  include it.  However, POSIX.2 does reserve the namespace of command names
  21534.  ending with a colon.  It is anticipated that a future implementation
  21535.  could take advantage of this and provide something like:
  21536.  
  21537.        outofloop: for i in a b c d e                                        1
  21538.        do
  21539.                for j in 0 1 2 3 4 5 6 7 8 9
  21540.                do
  21541.                        if test -r "${i}${j}"
  21542.                        then break outofloop
  21543.                        fi
  21544.                done
  21545.        done
  21546.  
  21547.  and that this might be standardized after implementation experience is
  21548.  achieved.
  21549.  
  21550.  END_RATIONALE
  21551.  
  21552.  
  21553.  3.14.2  colon - Null utility
  21554.  
  21555.        : [_a_r_g_u_m_e_n_t ...]
  21556.  
  21557.  This utility shall only expand command _a_r_g_u_m_e_n_ts.
  21558.  
  21559.  _E_x_i_t__S_t_a_t_u_s
  21560.  
  21561.  Zero.
  21562.  
  21563.  BEGIN_RATIONALE
  21564.  
  21565.  
  21566.  
  21567.  
  21568.  
  21569.  
  21570.  
  21571.  
  21572.  
  21573.                Copyright c 1991 IEEE.  All rights reserved.
  21574.       This is an unapproved IEEE Standards Draft, subject to change.
  21575.  
  21576.  
  21577.  
  21578.  
  21579.  
  21580.  3.14 Special Built-in Utilities                                       297
  21581.  
  21582.  
  21583.  
  21584.  
  21585.  
  21586.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21587.  
  21588.  3.14.2.1  colon Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21589.  
  21590.  The colon (:), or null utility, is used when a command is needed, as in
  21591.  the then condition of an if command, but nothing is to be done by the
  21592.  command.
  21593.  
  21594.  Example:
  21595.  
  21596.        : ${X=abc}
  21597.        if      false
  21598.        then    :
  21599.        else    echo $X
  21600.        fi
  21601.        abc
  21602.  
  21603.  As with any of the special built-ins, the null utility can also have
  21604.  variable assignments and redirections associated with it, such as:
  21605.  
  21606.        x=y : > z
  21607.  
  21608.  which sets variable x to the value y (so that it persists after the null
  21609.  utility ``completes'') and creates or truncates file z.
  21610.  
  21611.  END_RATIONALE
  21612.  
  21613.  
  21614.  3.14.3  continue - Continue for, while, or until loop
  21615.  
  21616.        continue [_n]
  21617.  
  21618.  The continue utility shall return to the top of the smallest enclosing
  21619.  for, while, or until, loop, or to the top of the _nth enclosing loop, if _n
  21620.  is specified.  This involves repeating the condition list of a while or
  21621.  until loop or performing the next assignment of a for loop, and
  21622.  reexecuting the loop if appropriate.
  21623.  
  21624.  The value of _n is a decimal integer _> 1.  The default is equivalent to
  21625.  _n=1.  If _n is greater than the number of enclosing loops, the last
  21626.  enclosing loop is used.
  21627.  
  21628.  _E_x_i_t__S_t_a_t_u_s
  21629.  
  21630.      0    Successful completion.                                            2
  21631.  
  21632.     >0    The _n value was not an unsigned decimal integer _> 1.              2
  21633.  
  21634.  BEGIN_RATIONALE
  21635.  
  21636.  
  21637.  
  21638.  
  21639.                Copyright c 1991 IEEE.  All rights reserved.
  21640.       This is an unapproved IEEE Standards Draft, subject to change.
  21641.  
  21642.  
  21643.  
  21644.  
  21645.  
  21646.  298                                              3 Shell Command Language
  21647.  
  21648.  
  21649.  
  21650.  
  21651.  
  21652.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21653.  
  21654.  3.14.3.1  continue Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21655.  
  21656.  Example:
  21657.  
  21658.        for i in *
  21659.        do
  21660.                if test -d "$i"
  21661.                then continue
  21662.                fi
  21663.        done
  21664.  
  21665.  END_RATIONALE
  21666.  
  21667.  
  21668.  3.14.4  dot - Execute commands in current environment
  21669.  
  21670.        . _f_i_l_e
  21671.  
  21672.  The shell shall execute commands from the _f_i_l_e in the current
  21673.  environment.
  21674.  
  21675.  If _f_i_l_e does not contain a slash, the shell shall use the search path
  21676.  specified by PATH to find the directory containing _f_i_l_e. Unlike normal
  21677.  command search, however, the file searched for by the dot utility need
  21678.  not be executable.  If no readable file is found, a noninteractive shell
  21679.  shall abort; an interactive shell shall write a diagnostic message to
  21680.  standard error, but this condition shall not be considered a syntax
  21681.  error.
  21682.  
  21683.  _E_x_i_t__S_t_a_t_u_s
  21684.  
  21685.  Returns the value of the last command executed, or a zero exit status if
  21686.  no command is executed.
  21687.  
  21688.  BEGIN_RATIONALE
  21689.  
  21690.  
  21691.  3.14.4.1  dot Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21692.  
  21693.  Some older implementations searched the current directory for the _f_i_l_e,
  21694.  even if the value of PATH disallowed it.  This behavior was omitted from
  21695.  POSIX.2 due to concerns about introducing the susceptibility to trojan
  21696.  horses that the user might be trying to avoid by leaving dot out of PATH.
  21697.  
  21698.  The KornShell version of dot takes optional arguments that are set to the  1
  21699.  positional parameters.  This is a valid extension that allows a dot        1
  21700.  script to behave identically to a function.
  21701.  
  21702.  
  21703.  
  21704.  
  21705.                Copyright c 1991 IEEE.  All rights reserved.
  21706.       This is an unapproved IEEE Standards Draft, subject to change.
  21707.  
  21708.  
  21709.  
  21710.  
  21711.  
  21712.  3.14 Special Built-in Utilities                                       299
  21713.  
  21714.  
  21715.  
  21716.  
  21717.  
  21718.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21719.  
  21720.  Example:
  21721.  
  21722.        cat foobar
  21723.        foo=hello bar=world
  21724.        . foobar
  21725.        echo $foo $bar
  21726.        hello world
  21727.  
  21728.  END_RATIONALE
  21729.  
  21730.  
  21731.  3.14.5  eval - Construct command by concatenating arguments
  21732.  
  21733.        eval [_a_r_g_u_m_e_n_t ...]
  21734.  
  21735.  The eval utility shall construct a command by concatenating _a_r_g_u_m_e_n_ts
  21736.  together, separating each with a <space>.  The constructed command shall
  21737.  be read and executed by the shell.
  21738.  
  21739.  _E_x_i_t__S_t_a_t_u_s
  21740.  
  21741.  If there are no _a_r_g_u_m_e_n_ts, or only null arguments, eval shall return a
  21742.  zero exit status; otherwise, it shall return the exit status of the
  21743.  command defined by the string of concatenated _a_r_g_u_m_e_n_ts separated by
  21744.  spaces.
  21745.  
  21746.  BEGIN_RATIONALE
  21747.  
  21748.  
  21749.  3.14.5.1  eval Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21750.  
  21751.  Example:
  21752.  
  21753.        foo=10 x=foo
  21754.        y='$'$x
  21755.        echo $y
  21756.        $foo
  21757.        eval y='$'$x
  21758.        echo $y
  21759.        10
  21760.  
  21761.  END_RATIONALE
  21762.  
  21763.  
  21764.  
  21765.  
  21766.  
  21767.  
  21768.  
  21769.  
  21770.  
  21771.                Copyright c 1991 IEEE.  All rights reserved.
  21772.       This is an unapproved IEEE Standards Draft, subject to change.
  21773.  
  21774.  
  21775.  
  21776.  
  21777.  
  21778.  300                                              3 Shell Command Language
  21779.  
  21780.  
  21781.  
  21782.  
  21783.  
  21784.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21785.  
  21786.  3.14.6  exec - Execute commands and open, close, and/or copy file
  21787.          descriptors
  21788.  
  21789.        exec [_c_o_m_m_a_n_d [_a_r_g_u_m_e_n_t ...]]
  21790.  
  21791.  The exec utility opens, closes, and/or copies file descriptors as
  21792.  specified by any redirections as part of the command.
  21793.  
  21794.  If exec is specified without _c_o_m_m_a_n_d or _a_r_g_u_m_e_n_t_s, and any file
  21795.  descriptors with numbers > 2 are opened with associated redirection
  21796.  statements, it is unspecified whether those file descriptors remain open
  21797.  when the shell invokes another utility.
  21798.  
  21799.  If exec is specified with _c_o_m_m_a_n_d, it shall replace the shell with
  21800.  _c_o_m_m_a_n_d without creating a new process.  If _a_r_g_u_m_e_n_ts are specified, they
  21801.  are arguments to _c_o_m_m_a_n_d.  Redirection shall affect the current shell
  21802.  execution environment.
  21803.  
  21804.  _E_x_i_t__S_t_a_t_u_s
  21805.  
  21806.  If _c_o_m_m_a_n_d is specified, exec shall not return to the shell; rather, the   2
  21807.  exit status of the process shall be the exit status of the program         2
  21808.  implementing _c_o_m_m_a_n_d, which overlaid the shell.  If _c_o_m_m_a_n_d is not found,  2
  21809.  the exit status shall be 127.  If _c_o_m_m_a_n_d is found, but it is not an       1
  21810.  executable utility, the exit status shall be 126.  If a redirection error  1
  21811.  occurs (see 3.8.1), the shell shall exit with a value in the range 1-125.  1
  21812.  Otherwise, exec shall return a zero exit status.
  21813.  
  21814.  BEGIN_RATIONALE
  21815.  
  21816.  
  21817.  3.14.6.1  exec Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21818.  
  21819.  Most historical implementations are not conformant in that
  21820.  
  21821.        foo=bar exec cmd
  21822.  
  21823.  does not pass foo to cmd.
  21824.  
  21825.  Earlier drafts stated that ``If specified without _c_o_m_m_a_n_d or _a_r_g_u_m_e_n_t,
  21826.  the shell sets to close-on-exec file numbers greater than 2 that are
  21827.  opened in this way, so that they will be closed when the shell invokes
  21828.  another program.''  This was based on the behavior of one version of the
  21829.  KornShell and was made unspecified when it was realized that some
  21830.  existing scripts relied on the more generally historical behavior
  21831.  (leaving all file descriptors open).  Furthermore, since the application
  21832.  should have no cognizance of whether a new shell is simply _f_o_r_k()ed,
  21833.  rather than _e_x_e_c()ed, it could not consistently rely on the automatic
  21834.  closing behavior anyway.  Scripts concerned that child shells could
  21835.  misuse open file descriptors can always close them explicitly, as shown
  21836.  
  21837.                Copyright c 1991 IEEE.  All rights reserved.
  21838.       This is an unapproved IEEE Standards Draft, subject to change.
  21839.  
  21840.  
  21841.  
  21842.  
  21843.  
  21844.  3.14 Special Built-in Utilities                                       301
  21845.  
  21846.  
  21847.  
  21848.  
  21849.  
  21850.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21851.  
  21852.  in one of the following examples.
  21853.  
  21854.  Examples:
  21855.  
  21856.  Open readfile as file descriptor 3 for reading:
  21857.  
  21858.        exec 3< readfile
  21859.  
  21860.  Open writefile as file descriptor 4 for writing:
  21861.  
  21862.        exec 4> writefile
  21863.  
  21864.  Make unit 5 a copy of unit 0:
  21865.  
  21866.        exec 5<&0
  21867.  
  21868.  Close file unit 3:
  21869.  
  21870.        exec 3<&-
  21871.  
  21872.  Cat the file maggie by replacing the current shell with the cat utility:
  21873.  
  21874.        exec cat maggie
  21875.  
  21876.  END_RATIONALE
  21877.  
  21878.  
  21879.  3.14.7  exit - Cause the shell to exit
  21880.  
  21881.        exit [_n]
  21882.  
  21883.  The exit utility shall cause the shell to exit with the exit status
  21884.  specified by the unsigned decimal integer _n.  If _n is specified, but its   1
  21885.  value is not between 0 and 255 inclusively, the exit status is undefined.  1
  21886.  
  21887.  A trap on EXIT shall be executed before the shell terminates, except when
  21888.  the exit utility is invoked in that trap itself, in which case the shell
  21889.  shall exit immediately.
  21890.  
  21891.  _E_x_i_t__S_t_a_t_u_s
  21892.  
  21893.  The exit status shall be _n, if specified.  Otherwise, the value shall be
  21894.  the exit value of the last command executed, or zero if no command was
  21895.  executed.  When exit is executed in a trap action (see 3.14.13), the
  21896.  ``last command'' is considered to be the command that executed
  21897.  immediately preceding the trap action.
  21898.  
  21899.  BEGIN_RATIONALE
  21900.  
  21901.  
  21902.  
  21903.                Copyright c 1991 IEEE.  All rights reserved.
  21904.       This is an unapproved IEEE Standards Draft, subject to change.
  21905.  
  21906.  
  21907.  
  21908.  
  21909.  
  21910.  302                                              3 Shell Command Language
  21911.  
  21912.  
  21913.  
  21914.  
  21915.  
  21916.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  21917.  
  21918.  3.14.7.1  exit Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21919.  
  21920.  As explained in other clauses, certain exit status values have been        1
  21921.  reserved for special uses and should be used by applications only for      1
  21922.  those purposes:                                                            1
  21923.  
  21924.      126  A file to be executed was found, but it was not an executable     1
  21925.           utility.                                                          1
  21926.  
  21927.      127  A utility to be executed was not found.                           1
  21928.  
  21929.     >128  A command was interrupted by a signal.                            1
  21930.  
  21931.  Examples:
  21932.  
  21933.  Exit with a _t_r_u_e value:
  21934.  
  21935.        exit 0
  21936.  
  21937.  Exit with a _f_a_l_s_e value:
  21938.  
  21939.        exit 1
  21940.  
  21941.  END_RATIONALE
  21942.  
  21943.  
  21944.  3.14.8  export - Set export attribute for variables
  21945.  
  21946.        export _n_a_m_e[=_w_o_r_d]...
  21947.        export -p
  21948.  
  21949.  The shell shall give the export attribute to the variables corresponding
  21950.  to the specified _n_a_m_es, which shall cause them to be in the environment
  21951.  of subsequently executed commands.
  21952.  
  21953.  When -p is specified, export shall write to the standard output the names
  21954.  and values of all exported variables, in the following format:             1
  21955.  
  21956.        "export %s=%s\n", <_n_a_m_e>, <_v_a_l_u_e>
  21957.  
  21958.  The shell shall format the output, including the proper use of quoting,
  21959.  so that it is suitable for re-input to the shell as commands that achieve
  21960.  the same exporting results.
  21961.  
  21962.  The export special built-in shall conform to the utility argument syntax
  21963.  guidelines described in 2.10.2.
  21964.  
  21965.  
  21966.  
  21967.  
  21968.  
  21969.                Copyright c 1991 IEEE.  All rights reserved.
  21970.       This is an unapproved IEEE Standards Draft, subject to change.
  21971.  
  21972.  
  21973.  
  21974.  
  21975.  
  21976.  3.14 Special Built-in Utilities                                       303
  21977.  
  21978.  
  21979.  
  21980.  
  21981.  
  21982.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  21983.  
  21984.  _E_x_i_t__S_t_a_t_u_s
  21985.  
  21986.  Zero.
  21987.  
  21988.  BEGIN_RATIONALE
  21989.  
  21990.  
  21991.  3.14.8.1  export Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  21992.  
  21993.  When no arguments are given, the results are unspecified.  Some
  21994.  historical shells use the no-argument case as the functional equivalent
  21995.  of what is required here with -p.  This feature was left unspecified
  21996.  because it is not existing practice in all shells and some scripts may
  21997.  rely on the now-unspecified results on their implementations.  Attempts
  21998.  to specify the -p output as the default case were unsuccessful in
  21999.  achieving consensus.  The -p option was added to allow portable access to
  22000.  the values that can be saved and then later restored using, for instance,
  22001.  a dot script.
  22002.  
  22003.  Examples:
  22004.  
  22005.  Export PWD and HOME variables:
  22006.  
  22007.        export PWD HOME
  22008.  
  22009.  Set and export the PATH variable:
  22010.  
  22011.        export PATH=/local/bin:$PATH
  22012.  
  22013.  Save and restore all exported variables:
  22014.  
  22015.        export -p > _t_e_m_p-_f_i_l_e
  22016.        unset _a _l_o_t _o_f _v_a_r_i_a_b_l_e_s
  22017.        ... _p_r_o_c_e_s_s_i_n_g
  22018.        . _t_e_m_p-_f_i_l_e
  22019.  
  22020.  END_RATIONALE
  22021.  
  22022.  
  22023.  3.14.9  readonly - Set read-only attribute for variables                   1
  22024.  
  22025.        readonly _n_a_m_e[=_w_o_r_d]...
  22026.        readonly -p
  22027.  
  22028.  The variables whose _n_a_m_es are specified shall be given the readonly
  22029.  attribute.  The values of variables with the read-only attribute cannot
  22030.  be changed by subsequent assignment, nor can those variables be unset by
  22031.  the unset utility.
  22032.  
  22033.  
  22034.  
  22035.                Copyright c 1991 IEEE.  All rights reserved.
  22036.       This is an unapproved IEEE Standards Draft, subject to change.
  22037.  
  22038.  
  22039.  
  22040.  
  22041.  
  22042.  304                                              3 Shell Command Language
  22043.  
  22044.  
  22045.  
  22046.  
  22047.  
  22048.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22049.  
  22050.  When -p is specified, readonly shall write to the standard output the
  22051.  names and values of all read-only variables, in the following format:      1
  22052.  
  22053.        "readonly %s=%s\n", <_n_a_m_e>, <_v_a_l_u_e>
  22054.  
  22055.  The shell shall format the output, including the proper use of quoting,
  22056.  so that it is suitable for re-input to the shell as commands that achieve
  22057.  the same attribute-setting results.
  22058.  
  22059.  The readonly special built-in shall conform to the utility argument
  22060.  syntax guidelines described in 2.10.2.
  22061.  
  22062.  _E_x_i_t__S_t_a_t_u_s
  22063.  
  22064.  Zero.
  22065.  
  22066.  BEGIN_RATIONALE
  22067.  
  22068.  
  22069.  3.14.9.1  readonly Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22070.  
  22071.  Example:
  22072.  
  22073.        readonly HOME PWD
  22074.  
  22075.  Some versions of the shell exist that preserve the read-only attribute
  22076.  across separate invocations.  POSIX.2 allows this behavior, but does not
  22077.  require it.
  22078.  
  22079.  See the rationale for export (3.14.8.1) for a description of the no-
  22080.  argument and -p output cases.
  22081.  
  22082.  In a previous draft, read-only functions were considered, but they were
  22083.  omitted as not being existing practice or particularly useful.
  22084.  Furthermore, functions must not be readonly across invocations to
  22085.  preclude _s_p_o_o_f_i_n_g (spoofing is the term for the practice of creating a
  22086.  program that acts like a well-known utility with the intent of subverting
  22087.  the user's real intent) of administrative or security-relevant (or
  22088.  -conscious) shell scripts.
  22089.  
  22090.  END_RATIONALE
  22091.  
  22092.  
  22093.  3.14.10  return - Return from a function
  22094.  
  22095.        return [_n]
  22096.  
  22097.  The return utility shall cause the shell to stop executing the current
  22098.  function or dot script (see 3.14.4).  If the shell is not currently
  22099.  executing a function or dot script, the results are unspecified.
  22100.  
  22101.                Copyright c 1991 IEEE.  All rights reserved.
  22102.       This is an unapproved IEEE Standards Draft, subject to change.
  22103.  
  22104.  
  22105.  
  22106.  
  22107.  
  22108.  3.14 Special Built-in Utilities                                       305
  22109.  
  22110.  
  22111.  
  22112.  
  22113.  
  22114.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22115.  
  22116.  _E_x_i_t__S_t_a_t_u_s
  22117.  
  22118.  The value of the special parameter ? shall be set to _n, an unsigned
  22119.  decimal integer, or to the exit status of the last command executed if _n
  22120.  is not specified.  If the value of _n is greater than 255, the results are
  22121.  undefined.  When return is executed in a trap action (see 3.14.13), the
  22122.  ``last command'' is considered to be the command that executed
  22123.  immediately preceding the trap action.
  22124.  
  22125.  BEGIN_RATIONALE
  22126.  
  22127.  
  22128.  3.14.10.1  return Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22129.  
  22130.  The behavior of return when not in a function or dot script differs
  22131.  between the System V shell and the KornShell.  In the System V shell this
  22132.  is an error, whereas in the KornShell, the effect is the same as exit.
  22133.  
  22134.  The results of returning a number greater than 255 are undefined because
  22135.  of differing practices in the various historical implementations.  Some
  22136.  shells AND out all but the low order 8 bits; others allow larger values,
  22137.  but not of unlimited size.
  22138.  
  22139.  See the discussion of appropriate exit status values in 3.14.7.1.          1
  22140.  
  22141.  END_RATIONALE                                                              1
  22142.  
  22143.  
  22144.  3.14.11  set - Set/unset options and positional parameters
  22145.  
  22146.        set [-aCefnuvx] [_a_r_g_u_m_e_n_t ...]
  22147.        set [+aCefnuvx] [_a_r_g_u_m_e_n_t ...]
  22148.        set -- [_a_r_g_u_m_e_n_t ...]
  22149.  
  22150.        _O_b_s_o_l_e_s_c_e_n_t _v_e_r_s_i_o_n:
  22151.  
  22152.        set - [_a_r_g_u_m_e_n_t ...]
  22153.  
  22154.  If no options or _a_r_g_u_m_e_n_ts are specified, set shall write the names and
  22155.  values of all shell variables in the collation sequence of the current
  22156.  locale.  Each _n_a_m_e shall start on a separate line, using the format:
  22157.  
  22158.        "%s=%s\n", <_n_a_m_e>, <_v_a_l_u_e>
  22159.  
  22160.  The _v_a_l_u_e string shall be written with appropriate quoting so that it is
  22161.  suitable for re-input to the shell, (re)setting, as far as possible, the   1
  22162.  variables that are currently set.  Readonly variables cannot be reset.     1
  22163.  See the description of shell quoting in 3.2.
  22164.  
  22165.  
  22166.  
  22167.                Copyright c 1991 IEEE.  All rights reserved.
  22168.       This is an unapproved IEEE Standards Draft, subject to change.
  22169.  
  22170.  
  22171.  
  22172.  
  22173.  
  22174.  306                                              3 Shell Command Language
  22175.  
  22176.  
  22177.  
  22178.  
  22179.  
  22180.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22181.  
  22182.  When options are specified, they shall set or unset attributes of the
  22183.  shell, as described below.  When _a_r_g_u_m_e_n_ts are specified, they shall
  22184.  cause positional parameters to be set or unset, as described below.
  22185.  Setting/unsetting attributes and positional parameters are not
  22186.  necessarily related actions, but they can be combined in a single
  22187.  invocation of set.
  22188.  
  22189.  The set utility shall conform to the utility argument syntax guidelines
  22190.  described in 2.10.2, except that options can be specified with either a
  22191.  leading hyphen (meaning enable the option) or plus-sign (meaning disable
  22192.  it).
  22193.  
  22194.  The implementation shall support the options in the following list in
  22195.  both their hyphen and plus-sign forms.  These options can also be
  22196.  specified as options to sh; see 4.56.
  22197.  
  22198.     -a          When this option is on, the export attribute shall be set
  22199.                 for each variable to which an assignment is performed.
  22200.                 (See 3.1.15.)  If the assignment precedes a utility name
  22201.                 in a command, the export attributes shall not persist in    1
  22202.                 the current execution environment after the utility         1
  22203.                 completes, with the exception that preceding one of the     1
  22204.                 special built-in utilities shall cause the export
  22205.                 attribute to persist after the built-in has completed.  If
  22206.                 the assignment does not precede a utility name in the
  22207.                 command, or if the assignment is a result of the operation
  22208.                 of the getopts or read utilities (see 4.27 and 4.52), the
  22209.                 export attribute shall persist until the variable is
  22210.                 unset.
  22211.  
  22212.     -C          (Uppercase C.)  Prevent existing files from being
  22213.                 overwritten by the shell's > redirection operator (see
  22214.                 3.7.2); the >| redirection operator shall override this
  22215.                 ``noclobber'' option for an individual file.
  22216.  
  22217.     -e          When this option is on, if a simple command fails for any   1
  22218.                 of the reasons listed in 3.8.1 or returns an exit status    1
  22219.                 value >0, and is not part of the compound list following a  1
  22220.                 while, until, or if keyword, and is not a part of an AND    1
  22221.                 or OR list, and is not a pipeline preceded by the !
  22222.                 reserved word, then the shell immediately shall exit.
  22223.  
  22224.     -f          The shell shall disable pathname expansion.
  22225.  
  22226.     -n          The shell shall read commands but not execute them; this
  22227.                 can be used to check for shell script syntax errors.  An
  22228.                 interactive shell may ignore this option.
  22229.  
  22230.  
  22231.  
  22232.  
  22233.                Copyright c 1991 IEEE.  All rights reserved.
  22234.       This is an unapproved IEEE Standards Draft, subject to change.
  22235.  
  22236.  
  22237.  
  22238.  
  22239.  
  22240.  3.14 Special Built-in Utilities                                       307
  22241.  
  22242.  
  22243.  
  22244.  
  22245.  
  22246.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22247.  
  22248.     -u          The shell shall write a message to standard error when it
  22249.                 tries to expand a variable that is not set and immediately
  22250.                 exit.  An interactive shell shall not exit.
  22251.  
  22252.     -v          The shell shall write its input to standard error as it is
  22253.                 read.
  22254.  
  22255.     -x          The shell shall write to standard error a trace for each
  22256.                 command after it expands the command and before it
  22257.                 executes it.
  22258.  
  22259.  The default for all these options is off (unset) unless the shell was
  22260.  invoked with them on (see sh in 4.56).  All the positional parameters
  22261.  shall be unset before any new values are assigned.
  22262.  
  22263.  The remaining arguments shall be assigned in order to the positional
  22264.  parameters.  The special parameter # shall be set to reflect the number
  22265.  of positional parameters.
  22266.  
  22267.  The special argument "--" immediately following the set command name can
  22268.  be used to delimit the arguments if the first argument begins with + or
  22269.  -, or to prevent inadvertent listing of all shell variables when there
  22270.  are no arguments.  The command set -- without _a_r_g_u_m_e_n_ts shall unset all
  22271.  positional parameters and set the special parameter # to zero.
  22272.  
  22273.  In the obsolescent version, the set command name followed by - with no
  22274.  other arguments shall turn off the -v and -x options without changing the
  22275.  positional parameters.  The set command name followed by - with other
  22276.  arguments shall turn off the -v and -x options and assign the arguments
  22277.  to the positional parameters in order.
  22278.  
  22279.  _E_x_i_t__S_t_a_t_u_s
  22280.  
  22281.  Zero.
  22282.  
  22283.  BEGIN_RATIONALE
  22284.  
  22285.  
  22286.  3.14.11.1  set Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22287.  
  22288.  The set -- form is listed specifically in the Synopsis even though this
  22289.  usage is implied by the utility syntax guidelines.  The explanation of
  22290.  this feature removes any ambiguity about whether the set -- form might be
  22291.  misinterpreted as being equivalent to set without any options or
  22292.  arguments.  The functionality of this form has been adopted from the
  22293.  KornShell.  In System V, set -- only unsets parameters if there is at
  22294.  least one argument; the only way to unset all parameters is to use shift.
  22295.  Using the KornShell version should not affect System V scripts because
  22296.  there should be no reason to deliberately issue it without arguments; if
  22297.  it were issued as, say:
  22298.  
  22299.                Copyright c 1991 IEEE.  All rights reserved.
  22300.       This is an unapproved IEEE Standards Draft, subject to change.
  22301.  
  22302.  
  22303.  
  22304.  
  22305.  
  22306.  308                                              3 Shell Command Language
  22307.  
  22308.  
  22309.  
  22310.  
  22311.  
  22312.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22313.  
  22314.        set -- "$@"                                                          1
  22315.  
  22316.  and there were in fact no arguments resulting from $@, unsetting the       1
  22317.  parameters would be a no-op anyway.
  22318.  
  22319.  The set + form in earlier drafts was omitted as being an unnecessary
  22320.  duplication of set alone and not widespread historical practice.
  22321.  
  22322.  The noclobber option was changed to -C from the set -o noclobber option
  22323.  in previous drafts.  The set -o is used in the KornShell to accept word-
  22324.  length option names, duplicating many of the single-letter names.  The
  22325.  noclobber option was changed to a single letter so that the historical $-
  22326.  paradigm would not be broken; see 3.5.2.
  22327.  
  22328.  The following set flags were intentionally omitted with the following
  22329.  rationale:
  22330.  
  22331.     -h    This flag is related to command name hashing, which is not
  22332.           required for an implementation.  It is primarily a performance
  22333.           issue, which is outside the scope of this standard.
  22334.  
  22335.     -k    The -k flag was originally added by Bourne to make it easier for
  22336.           users of prerelease versions of the shell.  In early versions of
  22337.           the Bourne shell the construct set name=value, had to be used to
  22338.           assign values to shell variables.  The problem with -k is that
  22339.           the behavior affects parsing, virtually precluding writing any
  22340.           compilers.  To explain the behavior of -k, it is necessary to
  22341.           describe the parsing algorithm, which is implementation defined.
  22342.           For example,
  22343.  
  22344.                 set -k; echo name=value
  22345.  
  22346.           and
  22347.  
  22348.                 set -k
  22349.                 echo name=value
  22350.  
  22351.           behave differently.  The interaction with functions is even more
  22352.           complex.  What is more, the -k flag is never needed, since the
  22353.           command line could have been reordered.
  22354.  
  22355.     -t    The -t flag is hard to specify and almost never used.  The only
  22356.           known use could be done with here-documents.  Moreover, the
  22357.           behavior with ksh and sh differ.  The man page says that it
  22358.           exits after reading and executing one command.  What is one
  22359.           command?  If the input is date;date, sh executes both date
  22360.           commands, ksh does only the first.
  22361.  
  22362.  
  22363.  
  22364.  
  22365.                Copyright c 1991 IEEE.  All rights reserved.
  22366.       This is an unapproved IEEE Standards Draft, subject to change.
  22367.  
  22368.  
  22369.  
  22370.  
  22371.  
  22372.  3.14 Special Built-in Utilities                                       309
  22373.  
  22374.  
  22375.  
  22376.  
  22377.  
  22378.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22379.  
  22380.  Consideration was given to rewriting set to simplify its confusing
  22381.  syntax.  A specific suggestion was that the unset utility should be used
  22382.  to unset options instead of using the non-_g_e_t_o_p_t()-able +_o_p_t_i_o_n syntax.
  22383.  However, the conclusion was reached that people were satisfied with the
  22384.  existing practice of using +_o_p_t_i_o_n and there was no compelling reason to
  22385.  modify such widespread existing practice.
  22386.  
  22387.  Examples:
  22388.  
  22389.  Write out all variables and their values:
  22390.  
  22391.        set
  22392.  
  22393.  Set $1, $2, and $3 and set $# to 3:
  22394.  
  22395.        set c a b
  22396.  
  22397.  Turn on the -x and -v options:
  22398.  
  22399.        set -xv
  22400.  
  22401.  Unset all positional parameters:
  22402.  
  22403.        set --
  22404.  
  22405.  Set $1 to the value of x, even if x begins with - or +:
  22406.  
  22407.        set -- "$x"
  22408.  
  22409.  Set the positional parameters to the expansion of x, even if x expands
  22410.  with a leading - or +:
  22411.  
  22412.        set -- $x
  22413.  
  22414.  END_RATIONALE
  22415.  
  22416.  
  22417.  3.14.12  shift - Shift positional parameters
  22418.  
  22419.        shift [_n]
  22420.  
  22421.  The positional parameters shall be shifted.  Positional parameter 1 shall
  22422.  be assigned the value of parameter (1+_n), parameter 2 shall be assigned
  22423.  the value of parameter (2+_n), and so forth.  The parameters represented
  22424.  by the numbers $# down to $#-_n+1 shall be unset, and the parameter #
  22425.  shall be updated to reflect the new number of positional parameters.
  22426.  
  22427.  The value _n shall be an unsigned decimal integer less than or equal to
  22428.  the value of the special parameter #.  If _n is not given, it shall be
  22429.  
  22430.  
  22431.                Copyright c 1991 IEEE.  All rights reserved.
  22432.       This is an unapproved IEEE Standards Draft, subject to change.
  22433.  
  22434.  
  22435.  
  22436.  
  22437.  
  22438.  310                                              3 Shell Command Language
  22439.  
  22440.  
  22441.  
  22442.  
  22443.  
  22444.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22445.  
  22446.  assumed to be 1.  If _n is 0, the positional and special parameters shall
  22447.  not be changed.
  22448.  
  22449.  _E_x_i_t__S_t_a_t_u_s
  22450.  
  22451.  The exit status shall be >0 if _n>$#; otherwise, it shall be zero.
  22452.  
  22453.  BEGIN_RATIONALE
  22454.  
  22455.  
  22456.  3.14.12.1  shift Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22457.  
  22458.  Example:
  22459.  
  22460.        set a b c d e
  22461.        shift 2
  22462.        echo $*
  22463.        c d e
  22464.  
  22465.  END_RATIONALE
  22466.  
  22467.  
  22468.  3.14.13  trap - Trap signals
  22469.  
  22470.        trap [_a_c_t_i_o_n _c_o_n_d_i_t_i_o_n ...]
  22471.  
  22472.  If _a_c_t_i_o_n is -, the shell shall reset each _c_o_n_d_i_t_i_o_n to the default
  22473.  value.  If _a_c_t_i_o_n is null (''), the shell shall ignore each of the
  22474.  specified _c_o_n_d_i_t_i_o_ns if they arise.  Otherwise, the argument _a_c_t_i_o_n shall
  22475.  be read and executed by the shell when one of the corresponding
  22476.  conditions arises.  The action of the trap shall override a previous
  22477.  action (either default action or one explicitly set).  The value of $?
  22478.  after the trap action completes shall be the value it had before the trap
  22479.  was invoked.
  22480.  
  22481.  The condition can be EXIT, 0 (equivalent to EXIT), or a signal specified
  22482.  using a symbolic name, without the SIG prefix, as listed in Required       1
  22483.  Signals and Job Control Signals (Table 3-1 and Table 3-2 in POSIX.1 {8}).
  22484.  (For example:  HUP, INT, QUIT, TERM).  Setting a trap for SIGKILL or
  22485.  SIGSTOP produces undefined results.
  22486.  
  22487.  The environment in which the shell executes a trap on EXIT shall be
  22488.  identical to the environment immediately after the last command executed
  22489.  before the trap on EXIT was taken.
  22490.  
  22491.  Each time the trap is invoked, the _a_c_t_i_o_n argument shall be processed in
  22492.  a manner equivalent to:
  22493.  
  22494.        eval "$action"
  22495.  
  22496.  
  22497.                Copyright c 1991 IEEE.  All rights reserved.
  22498.       This is an unapproved IEEE Standards Draft, subject to change.
  22499.  
  22500.  
  22501.  
  22502.  
  22503.  
  22504.  3.14 Special Built-in Utilities                                       311
  22505.  
  22506.  
  22507.  
  22508.  
  22509.  
  22510.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22511.  
  22512.  Signals that were ignored on entry to a noninteractive shell cannot be
  22513.  trapped or reset, although no error need be reported when attempting to
  22514.  do so.  An interactive shell may reset or catch signals ignored on entry.
  22515.  Traps shall remain in place for a given shell until explicitly changed
  22516.  with another trap command.
  22517.  
  22518.  The trap command with no arguments shall write to standard output a list
  22519.  of commands associated with each condition.  The format is:
  22520.  
  22521.        "trap -- %s %s ...\n", <_a_c_t_i_o_n>, <_c_o_n_d_i_t_i_o_n> ...                     1
  22522.  
  22523.  The shell shall format the output, including the proper use of quoting,
  22524.  so that it is suitable for re-input to the shell as commands that achieve
  22525.  the same trapping results.
  22526.  
  22527.  An implementation may allow numeric signal numbers for the conditions as
  22528.  an extension, if and only if the following map of signal numbers to names
  22529.  is true:
  22530.  
  22531.                   Signal   Signal        Signal   Signal
  22532.                   Number    Name         Number    Name
  22533.                   ______   _______       ______   _______
  22534.                     1      SIGHUP           9     SIGKILL
  22535.                     2      SIGINT          14     SIGALRM
  22536.                     3      SIGQUIT         15     SIGTERM
  22537.                     6      SIGABRT
  22538.  
  22539.  Otherwise, it shall be an error for the application to use numeric signal
  22540.  numbers.
  22541.  
  22542.  The trap special built-in shall conform to the utility argument syntax
  22543.  guidelines described in 2.10.2.
  22544.  
  22545.  _E_x_i_t__S_t_a_t_u_s
  22546.  
  22547.  If the trap name or number is invalid, a nonzero exit status shall be
  22548.  returned; otherwise, zero shall be returned.  For both interactive and
  22549.  noninteractive shells, invalid signal names or numbers shall not be
  22550.  considered a syntax error and shall not cause the shell to abort.
  22551.  
  22552.  BEGIN_RATIONALE
  22553.  
  22554.  3.14.13.1  trap Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22555.  
  22556.  Implementations may permit lowercase signal names as an extension.         1
  22557.  Implementations may also accept the names with the SIG prefix; no known    1
  22558.  historical shell does so.  The trap and kill utilities in POSIX.2 are now  1
  22559.  consistent in their omission of the SIG prefix for signal names.  Some     1
  22560.  kill implementations do not allow the prefix and kill -l lists the         1
  22561.  
  22562.  
  22563.                Copyright c 1991 IEEE.  All rights reserved.
  22564.       This is an unapproved IEEE Standards Draft, subject to change.
  22565.  
  22566.  
  22567.  
  22568.  
  22569.  
  22570.  312                                              3 Shell Command Language
  22571.  
  22572.  
  22573.  
  22574.  
  22575.  
  22576.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22577.  
  22578.  signals without prefixes.                                                  1
  22579.  
  22580.  As stated previously, when a subshell is entered, traps are set to the     1
  22581.  default actions.  This does not imply that the trap command cannot be      1
  22582.  used within the subshell to set new traps.                                 1
  22583.  
  22584.  Trapping SIGKILL or SIGSTOP is accepted by some historical
  22585.  implementations, but it does not work.  Portable POSIX.2 applications
  22586.  cannot try it.
  22587.  
  22588.  The output format is not historical practice.  Since the output of
  22589.  historical traps is not portable (because numeric signal values are not
  22590.  portable) and had to change to become so, an opportunity was taken to
  22591.  format the output in a way that a shell script could use to save and then
  22592.  later reuse a trap if it wanted.  For example:
  22593.  
  22594.        save_traps=$(trap)
  22595.        ...
  22596.        eval "$save_traps"
  22597.  
  22598.  The KornShell uses an ERR trap that is triggered whenever set -e would
  22599.  cause an exit.  This is allowable as an extension, but was not mandated,
  22600.  as other shells have not used it.
  22601.  
  22602.  The text about the environment for the EXIT trap invalidates the behavior
  22603.  of some historical versions of interactive shells which, e.g., close the
  22604.  standard input before executing a trap on 0.  For example, in some
  22605.  historical interactive shell sessions the following trap on 0 would
  22606.  always print --:
  22607.  
  22608.        trap 'read foo; echo "-$foo-"' 0
  22609.  
  22610.  Examples:
  22611.  
  22612.  Write out a list of all traps and actions:
  22613.  
  22614.        trap
  22615.  
  22616.  Set a trap so the logout utility in the HOME directory will execute when
  22617.  the shell terminates:
  22618.  
  22619.        trap '$HOME/logout' EXIT
  22620.  
  22621.        _o_r
  22622.        trap '$HOME/logout' 0
  22623.  
  22624.  Unset traps on INT, QUIT, TERM, and EXIT:
  22625.  
  22626.  
  22627.  
  22628.  
  22629.                Copyright c 1991 IEEE.  All rights reserved.
  22630.       This is an unapproved IEEE Standards Draft, subject to change.
  22631.  
  22632.  
  22633.  
  22634.  
  22635.  
  22636.  3.14 Special Built-in Utilities                                       313
  22637.  
  22638.  
  22639.  
  22640.  
  22641.  
  22642.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22643.  
  22644.        trap - INT QUIT TERM EXIT
  22645.  
  22646.  END_RATIONALE
  22647.  
  22648.  
  22649.  3.14.14  unset - Unset values and attributes of variables and functions
  22650.  
  22651.        unset  [-fv] _n_a_m_e ...                                                1
  22652.  
  22653.  Each variable or function specified by _n_a_m_e shall be unset.
  22654.  
  22655.  If -v is specified, _n_a_m_e refers to a variable name and the shell shall     1
  22656.  unset it and remove it from the environment.  Read-only variables cannot   1
  22657.  be unset.                                                                  1
  22658.  
  22659.  If -f is specified, _n_a_m_e refers to a function and the shell shall unset    1
  22660.  the function definition.                                                   1
  22661.  
  22662.  If neither -f nor -v is specified, _n_a_m_e refers to a variable; if a         1
  22663.  variable by that name does not exist, it is unspecified whether a          1
  22664.  function by that name, if any, shall be unset.                             1
  22665.  
  22666.  Unsetting a variable or function that was not previously set shall not be
  22667.  considered an error and shall not cause the shell to abort.                1
  22668.  
  22669.  The unset special built-in shall conform to the utility argument syntax
  22670.  guidelines described in 2.10.2.
  22671.  
  22672.  _E_x_i_t__S_t_a_t_u_s
  22673.  
  22674.      0    All _n_a_m_es were successfully unset.
  22675.  
  22676.     >0    At least one _n_a_m_e could not be unset.
  22677.  
  22678.  BEGIN_RATIONALE
  22679.  
  22680.  
  22681.  3.14.14.1  unset Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  22682.  
  22683.  Note that
  22684.  
  22685.        VARIABLE=
  22686.  
  22687.  is not equivalent to an unset of VARIABLE; in the example, VARIABLE is
  22688.  set to "".  Also, the ``variables'' that can be unset should not be
  22689.  misinterpreted to include the special parameters (see 3.5.2).
  22690.  
  22691.  Consideration was given to omitting the -f option in favor of an
  22692.  unfunction utility, but decided to retain existing practice.
  22693.  
  22694.  
  22695.                Copyright c 1991 IEEE.  All rights reserved.
  22696.       This is an unapproved IEEE Standards Draft, subject to change.
  22697.  
  22698.  
  22699.  
  22700.  
  22701.  
  22702.  314                                              3 Shell Command Language
  22703.  
  22704.  
  22705.  
  22706.  
  22707.  
  22708.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22709.  
  22710.  The -v option was introduced because System V historically used one name   1
  22711.  space for both variables and functions.  When unset is used without        1
  22712.  options, System V historically unset either a function or a variable and   1
  22713.  there was no confusion about which one was intended.  A portable POSIX.2   1
  22714.  application can use unset without an option to unset a variable, but not   1
  22715.  a function; the -f option must be used.                                    1
  22716.  
  22717.  Examples:
  22718.  
  22719.  Unset the VISUAL variable:
  22720.  
  22721.        unset -v VISUAL                                                      1
  22722.  
  22723.  Unset the functions foo and bar:
  22724.  
  22725.        unset -f foo bar
  22726.  
  22727.  END_RATIONALE
  22728.  
  22729.  
  22730.  
  22731.  
  22732.  
  22733.  
  22734.  
  22735.  
  22736.  
  22737.  
  22738.  
  22739.  
  22740.  
  22741.  
  22742.  
  22743.  
  22744.  
  22745.  
  22746.  
  22747.  
  22748.  
  22749.  
  22750.  
  22751.  
  22752.  
  22753.  
  22754.  
  22755.  
  22756.  
  22757.  
  22758.  
  22759.  
  22760.  
  22761.                Copyright c 1991 IEEE.  All rights reserved.
  22762.       This is an unapproved IEEE Standards Draft, subject to change.
  22763.  
  22764.  
  22765.  
  22766.  
  22767.  
  22768.  3.14 Special Built-in Utilities                                       315
  22769.  
  22770.  
  22771.  
  22772.  
  22773.  
  22774.  
  22775.  
  22776.  
  22777.  
  22778.  
  22779.  
  22780.  
  22781.  
  22782.  
  22783.  
  22784.  
  22785.  
  22786.  
  22787.  
  22788.  
  22789.  
  22790.  
  22791.  
  22792.  
  22793.  
  22794.  
  22795.  
  22796.  
  22797.  
  22798.  
  22799.  
  22800.  
  22801.  
  22802.  
  22803.  
  22804.  
  22805.  
  22806.  
  22807.  
  22808.  
  22809.  
  22810.  
  22811.  
  22812.  
  22813.  
  22814.  
  22815.  
  22816.  
  22817.  
  22818.  
  22819.  
  22820.  
  22821.  
  22822.  
  22823.  
  22824.  
  22825.  
  22826.  
  22827.  
  22828.  
  22829.  
  22830.  
  22831.  
  22832.  
  22833.  
  22834.  
  22835.  
  22836.  
  22837.  
  22838.  
  22839.  
  22840.                                                              P1003.2/D11.2
  22841.  
  22842.  
  22843.  
  22844.  
  22845.  
  22846.  
  22847.  
  22848.  
  22849.                 Section 4: Execution Environment Utilities
  22850.  
  22851.  
  22852.  
  22853.  The Execution Environment Utilities are the utilities that shall be
  22854.  implemented in all conforming POSIX.2 systems.
  22855.  
  22856.  
  22857.  
  22858.  4.1  awk - Pattern scanning and processing language
  22859.  
  22860.  
  22861.  4.1.1  Synopsis
  22862.  
  22863.  awk  [-F _E_R_E] [-v _a_s_s_i_g_n_m_e_n_t] ...  _p_r_o_g_r_a_m [_a_r_g_u_m_e_n_t ...]
  22864.  
  22865.  awk  [-F _E_R_E] -f _p_r_o_g_f_i_l_e ...  [-v _a_s_s_i_g_n_m_e_n_t] ...  [_a_r_g_u_m_e_n_t ...]
  22866.  
  22867.  
  22868.  4.1.2  Description
  22869.  
  22870.  The awk utility shall execute programs written in the _a_w_k programming
  22871.  language, which is specialized for textual data manipulation.  An awk
  22872.  program is a sequence of patterns and corresponding actions.  When input
  22873.  is read that matches a pattern, the action associated with that pattern
  22874.  shall be carried out.
  22875.  
  22876.  Input shall be interpreted as a sequence of records.  By default, a
  22877.  record is a line, but this can be changed by using the RS built-in
  22878.  variable.  Each record of input shall be matched in turn against each
  22879.  pattern in the program.  For each pattern matched, the associated action
  22880.  shall be executed.
  22881.  
  22882.  The awk utility shall interpret each input record as a sequence of fields
  22883.  where, by default, a field is a string of non-<blank> characters.  This
  22884.  default white space field delimiter can be changed by using the FS
  22885.  built-in variable or the -F _E_R_E.  The awk utility shall denote the first
  22886.  field in a record $1, the second $2, and so forth.  The symbol $0 shall
  22887.  refer to the entire record; setting any other field shall cause the
  22888.  reevaluation of $0.  Assigning to $0 shall reset the values of all other   1
  22889.  fields and the NF built-in variable.                                       1
  22890.  
  22891.  
  22892.  
  22893.                Copyright c 1991 IEEE.  All rights reserved.
  22894.       This is an unapproved IEEE Standards Draft, subject to change.
  22895.  
  22896.  
  22897.  
  22898.  
  22899.  
  22900.  4.1 awk - Pattern scanning and processing language                    317
  22901.  
  22902.  
  22903.  
  22904.  
  22905.  
  22906.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  22907.  
  22908.  4.1.3  Options
  22909.  
  22910.  The awk utility shall conform to the utility argument syntax guidelines
  22911.  described in 2.10.2.
  22912.  
  22913.  The following options shall be supported by the implementation:
  22914.  
  22915.     -F _E_R_E      Define the input field separator to be the extended
  22916.                 regular expression _E_R_E, before any input is read (see
  22917.                 4.1.7.4).
  22918.  
  22919.     -f _p_r_o_g_f_i_l_e Specifies the pathname of the file _p_r_o_g_f_i_l_e containing an
  22920.                 awk program.  If multiple instances of this option are
  22921.                 specified, the concatenation of the files specified as
  22922.                 _p_r_o_g_f_i_l_e in the order specified shall be the awk program.
  22923.                 The awk program can alternatively be specified in the
  22924.                 command line as a single argument.
  22925.  
  22926.     -v _a_s_s_i_g_n_m_e_n_t
  22927.                 The _a_s_s_i_g_n_m_e_n_t argument shall be in the same form as an
  22928.                 _a_s_s_i_g_n_m_e_n_t operand.  The specified variable assignment
  22929.                 shall occur prior to executing the awk program, including
  22930.                 the actions associated with BEGIN patterns (if any).
  22931.                 Multiple occurrences of this option can be specified.
  22932.  
  22933.  
  22934.  4.1.4  Operands
  22935.  
  22936.  The following operands shall be supported by the implementation:
  22937.  
  22938.     _p_r_o_g_r_a_m     If no -f option is specified, the first operand to awk
  22939.                 shall be the text of the awk program.  The application
  22940.                 shall supply the _p_r_o_g_r_a_m operand as a single argument to
  22941.                 awk.  If the text does not end in a <newline> character,
  22942.                 awk shall interpret the text as if it did.
  22943.  
  22944.     _a_r_g_u_m_e_n_t    Either of the following two types of _a_r_g_u_m_e_n_ts can be
  22945.                 intermixed:
  22946.  
  22947.                    _f_i_l_e  A pathname of a file that contains the input to
  22948.                          be read, which is matched against the set of
  22949.                          patterns in the program.  If no _f_i_l_e operands are
  22950.                          specified, or if a _f_i_l_e operand is -, the
  22951.                          standard input shall be used.
  22952.  
  22953.                    _a_s_s_i_g_n_m_e_n_t
  22954.                          An operand that begins with an underscore or
  22955.                          alphabetic character from the portable character
  22956.                          set (see Table 2-3 in 2.4), followed by a
  22957.  
  22958.  
  22959.                Copyright c 1991 IEEE.  All rights reserved.
  22960.       This is an unapproved IEEE Standards Draft, subject to change.
  22961.  
  22962.  
  22963.  
  22964.  
  22965.  
  22966.  318                                     4 Execution Environment Utilities
  22967.  
  22968.  
  22969.  
  22970.  
  22971.  
  22972.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  22973.  
  22974.                          sequence of underscores, digits, and alphabetics
  22975.                          from the portable character set, followed by the
  22976.                          = character shall specify a variable assignment
  22977.                          rather than a pathname.  The characters before
  22978.                          the = shall represent the name of an awk
  22979.                          variable; if that name is an awk reserved word
  22980.                          (see 4.1.7.7) the behavior is undefined.  The
  22981.                          characters following the equals-sign shall be
  22982.                          interpreted as if they appeared in the awk
  22983.                          program preceded and followed by a double-quote
  22984.                          (") character, as a STRING token (see 4.1.7.7),
  22985.                          except that if the last character is an unescaped
  22986.                          backslash, it shall be interpreted as a literal
  22987.                          backslash rather than as the first character of
  22988.                          the sequence ``\"''.  The variable shall be
  22989.                          assigned the value of that STRING token.  If that
  22990.                          value is considered a _n_u_m_e_r_i_c _s_t_r_i_n_g (see
  22991.                          4.1.7.2), the variable shall also be assigned its
  22992.                          numeric value.  Each such variable assignment
  22993.                          shall occur just prior to the processing of the
  22994.                          following _f_i_l_e, if any.  Thus, an assignment
  22995.                          before the first _f_i_l_e argument shall be executed
  22996.                          after the BEGIN actions (if any), while an
  22997.                          assignment after the last _f_i_l_e argument shall
  22998.                          occur before the END actions (if any).  If there
  22999.                          are no _f_i_l_e arguments, assignments shall be
  23000.                          executed before processing the standard input.
  23001.  
  23002.  
  23003.  4.1.5  External Influences
  23004.  
  23005.  
  23006.  4.1.5.1  Standard Input
  23007.  
  23008.  The standard input shall be used only if no _f_i_l_e operands are specified,
  23009.  or if a _f_i_l_e operand is -.  See Input Files.
  23010.  
  23011.  4.1.5.2  Input Files
  23012.  
  23013.  Input files to the awk program from any of the following sources:          1
  23014.  
  23015.      - Any _f_i_l_e operands or their equivalents, achieved by modifying the    1
  23016.        awk variables ARGV and ARGC                                          1
  23017.  
  23018.      - Standard input in the absence of any _f_i_l_e operands                   1
  23019.  
  23020.      - Arguments to the getline function                                    1
  23021.  
  23022.  
  23023.  
  23024.  
  23025.                Copyright c 1991 IEEE.  All rights reserved.
  23026.       This is an unapproved IEEE Standards Draft, subject to change.
  23027.  
  23028.  
  23029.  
  23030.  
  23031.  
  23032.  4.1 awk - Pattern scanning and processing language                    319
  23033.  
  23034.  
  23035.  
  23036.  
  23037.  
  23038.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23039.  
  23040.  shall be text files.  Whether the variable RS is set to a value other      1
  23041.  than <newline> or not, for these files, the implementation shall support   1
  23042.  records terminated with the specified separator up to {LINE_MAX} bytes     1
  23043.  and may support longer records.                                            1
  23044.  
  23045.  If -f _p_r_o_g_f_i_l_e is specified, the file(s) named by _p_r_o_g_f_i_l_e shall be text
  23046.  file(s) containing an awk program.
  23047.  
  23048.  
  23049.  4.1.5.3  Environment Variables
  23050.  
  23051.  The following environment variables shall affect the execution of awk:
  23052.  
  23053.     LANG               This variable shall determine the locale to use for
  23054.                        the locale categories when both LC_ALL and the
  23055.                        corresponding environment variable (beginning with
  23056.                        LC_) do not specify a locale.  See 2.6.
  23057.  
  23058.     LC_ALL             This variable shall determine the locale to be used
  23059.                        to override any values for locale categories
  23060.                        specified by the settings of LANG or any
  23061.                        environment variables beginning with LC_.
  23062.  
  23063.     LC_CTYPE           This variable shall determine the locale for the
  23064.                        interpretation of sequences of bytes of text data
  23065.                        as characters (e.g., single- versus multibyte
  23066.                        characters in arguments and input files), the
  23067.                        behavior of character classes within regular
  23068.                        expressions, the identification of characters as
  23069.                        letters, and the mapping of upper- and lowercase
  23070.                        characters for the toupper and tolower functions.
  23071.  
  23072.     LC_COLLATE         This variable shall determine the locale for the
  23073.                        behavior of ranges, equivalence classes, and
  23074.                        multicharacter collating elements within regular
  23075.                        expressions and in comparisons of string values.
  23076.  
  23077.     LC_MESSAGES        This variable shall determine the language in which
  23078.                        messages should be written.
  23079.  
  23080.     LC_NUMERIC         This variable shall determine the radix character
  23081.                        used when interpreting numeric input, performing
  23082.                        conversions between numeric and string values, and
  23083.                        formatting numeric output.
  23084.  
  23085.     PATH               This variable shall define the search path when
  23086.                        looking for commands executed by system(_e_x_p_r), or
  23087.                        input and output pipes.  See 2.6.
  23088.  
  23089.  
  23090.  
  23091.                Copyright c 1991 IEEE.  All rights reserved.
  23092.       This is an unapproved IEEE Standards Draft, subject to change.
  23093.  
  23094.  
  23095.  
  23096.  
  23097.  
  23098.  320                                     4 Execution Environment Utilities
  23099.  
  23100.  
  23101.  
  23102.  
  23103.  
  23104.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23105.  
  23106.  In addition, all environment variables shall be visible via the awk
  23107.  variable ENVIRON.
  23108.  
  23109.  
  23110.  4.1.5.4  Asynchronous Events
  23111.  
  23112.  Default.
  23113.  
  23114.  
  23115.  4.1.6  External Effects
  23116.  
  23117.  4.1.6.1  Standard Output
  23118.  
  23119.  The nature of the output files depends on the awk program.
  23120.  
  23121.  
  23122.  4.1.6.2  Standard Error
  23123.  
  23124.  Used only for diagnostic messages.
  23125.  
  23126.  4.1.6.3  Output Files
  23127.  
  23128.  The nature of the output files depends on the awk program.
  23129.  
  23130.  
  23131.  4.1.7  Extended Description
  23132.  
  23133.  
  23134.  4.1.7.1  Overall Program Structure
  23135.  
  23136.  An awk program is composed of pairs of the form:
  23137.  
  23138.        _p_a_t_t_e_r_n { _a_c_t_i_o_n }
  23139.  
  23140.  Either the pattern or the action (including the enclosing brace
  23141.  characters) can be omitted.
  23142.  
  23143.  A missing pattern shall match any record of input, and a missing action
  23144.  shall be equivalent to an action that writes the matched record of input
  23145.  to standard output.
  23146.  
  23147.  Execution of the awk program shall start by first executing the actions
  23148.  associated with all BEGIN patterns in the order they occur in the
  23149.  program.  Then each _f_i_l_e operand (or standard input if no files were
  23150.  specified) shall be processed in turn by reading data from the file until
  23151.  a record separator is seen (<newline> by default), splitting the current   1
  23152.  record into fields using the current value of FS according to the rules    1
  23153.  in 4.1.7.4, evaluating each pattern in the program in the order of         1
  23154.  occurrence, and executing the action associated with each pattern that
  23155.  matches the current record.  The action for a matching pattern shall be
  23156.  
  23157.                Copyright c 1991 IEEE.  All rights reserved.
  23158.       This is an unapproved IEEE Standards Draft, subject to change.
  23159.  
  23160.  
  23161.  
  23162.  
  23163.  
  23164.  4.1 awk - Pattern scanning and processing language                    321
  23165.  
  23166.  
  23167.  
  23168.  
  23169.  
  23170.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23171.  
  23172.  executed before evaluating subsequent patterns.  Last, the actions
  23173.  associated with all END patterns shall be executed in the order they
  23174.  occur in the program.
  23175.  
  23176.  
  23177.  4.1.7.2  Expressions
  23178.  
  23179.  
  23180.           Table 4-1  -  awk Expressions in Decreasing Precedence
  23181.  ___________________________________________________________________________
  23182.                                           Semantic        Type of
  23183.      Syntax              Name            Definition        Result      Assoc
  23184.  ___________________________________________________________________________
  23185.  (____e__x__p__r_)_______G_r_o_u_p_i_n_g_________________C__S_t_a_n_d_a_r_d__{_7_}_t_y_p_e__o_f____e__x__p__r______n_/_a___
  23186.  $_e_x_p_r         Field reference         4.1.7.2       string            n/a
  23187.  ___________________________________________________________________________
  23188.  ++ _l_v_a_l_u_e     Pre-increment           C Standard {7}numeric           n/a
  23189.  -- _l_v_a_l_u_e     Pre-decrement           C Standard {7}numeric           n/a
  23190.  _l_v_a_l_u_e ++     Post-increment          C Standard {7}numeric           n/a
  23191.  __l__v__a__l__u__e_-_-______P_o_s_t_-_d_e_c_r_e_m_e_n_t___________C__S_t_a_n_d_a_r_d__{_7_}_n_u_m_e_r_i_c____________n_/_a___
  23192.  _e_x_p_r ^ _e_x_p_r   Exponentiation          4.1.7.2       numeric           right
  23193.  ___________________________________________________________________________
  23194.  ! _e_x_p_r        Logical not             C Standard {7}numeric           n/a
  23195.  + _e_x_p_r        Unary plus              C Standard {7}numeric           n/a
  23196.  -____e__x__p__r________U_n_a_r_y__m_i_n_u_s______________C__S_t_a_n_d_a_r_d__{_7_}_n_u_m_e_r_i_c____________n_/_a___
  23197.  _e_x_p_r * _e_x_p_r   Multiplication          C Standard {7}numeric           left
  23198.  _e_x_p_r / _e_x_p_r   Division                C Standard {7}numeric           left
  23199.  _|e_x_p_r % _e_x_p_r   M|odulus                 4|.1.7.2       n|umeric           l|eft |
  23200.  _|______________|________________________|______________|__________________|____|
  23201.  _|e_x_p_r + _e_x_p_r   A|ddition                C| Standard {7}n|umeric           l|eft |
  23202.  _|_e__x__p__r_-____e__x__p__r___S|_u_b_t_r_a_c_t_i_o_n______________C|__S_t_a_n_d_a_r_d__{_7_}_n|_u_m_e_r_i_c____________l|_e_f_t__|
  23203.  _|e_x_p_r _e_x_p_r     S|tring concatenation    4|.1.7.2       s|tring            l|eft |
  23204.  _|______________|________________________|______________|__________________|____|
  23205.  _|e_x_p_r < _e_x_p_r   L|ess than               4|.1.7.2       n|umeric           n|one |
  23206.  _|e_x_p_r <= _e_x_p_r  L|ess than or equal to   4|.1.7.2       n|umeric           n|one |
  23207.  _|e_x_p_r != _e_x_p_r  N|ot equal to            4|.1.7.2       n|umeric           n|one |
  23208.  _|e_x_p_r == _e_x_p_r  E|qual to                4|.1.7.2       n|umeric           n|one |
  23209.  _|e_x_p_r > _e_x_p_r   G|reater than            4|.1.7.2       n|umeric           n|one |
  23210.  _|_e__x__p__r_>_=____e__x__p__r__G|_r_e_a_t_e_r__t_h_a_n__o_r__e_q_u_a_l__t_o_4|_._1_._7_._2________n|_u_m_e_r_i_c____________n|_o_n_e__|
  23211.  _|e_x_p_r   _e_x_p_r   E|RE match               4|.1.7.4       n|umeric           n|one |
  23212.  _|e_x_p_r ~!  _e_x_p_r  E|RE nonmatch            4|.1.7.4       n|umeric           n|one |
  23213.  _|_____~_________|________________________|______________|__________________|____|
  23214.  _|e_x_p_r in array A|rray membership        4|.1.7.2       n|umeric           l|eft |
  23215.  (| _i_n_d_e_x ) in  M|ultidimension array    4|.1.7.2       n|umeric           l|eft |
  23216.  _|_____a__r__r__a__y______|___m_e_m_b_e_r_s_h_i_p____________|______________|__________________|____|
  23217.  _|e_x_p_r && _e_x_p_r  L|ogical AND             C| Standard {7}n|umeric           l|eft 1|
  23218.  _|______________|________________________|______________|__________________|____1|
  23219.  _|_e__x__p__r_|_|____e__x__p__r__L|_o_g_i_c_a_l__O_R_______________C|__S_t_a_n_d_a_r_d__{_7_}_n|_u_m_e_r_i_c____________l|_e_f_t__1|1
  23220.  _|e_x_p_r_1 ? _e_x_p_r_2 C|onditional expression  C| Standard {7}t|ype of selected  r|ight1|
  23221.  |             |                       |             |                 |    |
  23222.  |             |                       |             |                 |    |
  23223.  |             C|opyright c 1991 IEEE.  A|ll rights rese|rved.            |    |
  23224.  |    This is an| unapproved IEEE Standar|ds Draft, subj|ect to change.   |    |
  23225.  |             |                       |             |                 |    |
  23226.  |             |                       |             |                 |    |
  23227.  |             |                       |             |                 |    |
  23228.  |             |                       |             |                 |    |
  23229.  |             |                       |             |                 |    |
  23230.  3|22           |                       | 4 Execution E|nvironment Utiliti|es  |
  23231.  |             |                       |             |                 |    |
  23232.  |             |                       |             |                 |    |
  23233.  |             |                       |             |                 |    |
  23234.  |             |                       |             |                 |    |
  23235.  |             |                       |             |                 |    |
  23236.  P|art 2: SHELL A|ND UTILITIES           |             |       P1003.2/D11|.2  |
  23237.  |             |                       |             |                 |    |
  23238.  |   : _e_x_p_r_3   |                       |             |   _e_x_p_r_2 or _e_x_p_r_3|    |
  23239.  _|______________|________________________|______________|__________________|____|
  23240.  _|l_v_a_l_u_e ^= _e_x_p_rE|xponentiation          4|.1.7.2       n|umeric           r|ight|
  23241.  |             a|ssignment              |             |                 |    |
  23242.  _|l_v_a_l_u_e %= _e_x_p_rM|odulus assignment      4|.1.7.2       n|umeric           r|ight|
  23243.  _|l_v_a_l_u_e *= _e_x_p_rM|ultiplication          C| Standard {7}n|umeric           r|ight|
  23244.  |             a|ssignment              |             |                 |    |
  23245.  _|l_v_a_l_u_e /= _e_x_p_rD|ivision assignment     C| Standard {7}n|umeric           r|ight|
  23246.  _|l_v_a_l_u_e += _e_x_p_rA|ddition assignment     C| Standard {7}n|umeric           r|ight|
  23247.  _|l_v_a_l_u_e -= _e_x_p_rS|ubtraction assignment  C| Standard {7}n|umeric           r|ight|
  23248.  _|_l__v__a__l__u__e_=____e__x__p__r_A|_s_s_i_g_n_m_e_n_t_______________C|__S_t_a_n_d_a_r_d__{_7_}_t|_y_p_e__o_f____e__x__p__r______r|_i_g_h_t_|
  23249.  
  23250.  
  23251.  
  23252.  
  23253.  Expressions describe computations used in _p_a_t_t_e_r_n_s and _a_c_t_i_o_n_s.  In
  23254.  Table 4-1, valid expression operations are given in groups from highest
  23255.  precedence first to lowest precedence last, with equal-precedence
  23256.  operators grouped between horizontal lines.  In expression evaluation,
  23257.  higher precedence operators shall be evaluated before lower precedence
  23258.  operators.  In this table _e_x_p_r, _e_x_p_r_1, _e_x_p_r_2, and _e_x_p_r_3 represent any
  23259.  expression, while _l_v_a_l_u_e represents any entity that can be assigned to
  23260.  (i.e., on the left side of an assignment operator).  The precise syntax
  23261.  of expressions is given in the grammar in 4.1.7.7.
  23262.  
  23263.  Each expression shall have either a string value, a numeric value, or
  23264.  both.  Except as stated for specific contexts, the value of an expression
  23265.  shall be implicitly converted to the type needed for the context in which
  23266.  it is used.  A string value shall be converted to a numeric value by the
  23267.  equivalent of the following calls to functions defined by the
  23268.  C Standard {7}:
  23269.  
  23270.        setlocale(LC_NUMERIC, "");
  23271.        _n_u_m_e_r_i_c__v_a_l_u_e = _a_t_o_f(_s_t_r_i_n_g__v_a_l_u_e);
  23272.  
  23273.  A numeric value that is exactly equal to the value of an integer (see
  23274.  2.9.2.1) shall be converted to a string by the equivalent of a call to
  23275.  the sprintf function (see 4.1.7.6.2) with the string "%d" as the _f_m_t
  23276.  argument and the numeric value being converted as the first and only _e_x_p_r
  23277.  argument.  Any other numeric value shall be converted to a string by the
  23278.  equivalent of a call to the sprintf function with the value of the
  23279.  variable CONVFMT as the _f_m_t argument and the numeric value being
  23280.  converted as the first and only _e_x_p_r argument.  The result of the          1
  23281.  conversion is unspecified if the value of CONVFMT is not a floating-point  1
  23282.  format specification.  This standard specifies no explicit conversions     1
  23283.  between numbers and strings.  An application can force an expression to
  23284.  be treated as a number by adding zero to it, or can force it to be
  23285.  treated as a string by concatenating the null string ("") to it.
  23286.  
  23287.  
  23288.  
  23289.                Copyright c 1991 IEEE.  All rights reserved.
  23290.       This is an unapproved IEEE Standards Draft, subject to change.
  23291.  
  23292.  
  23293.  
  23294.  
  23295.  
  23296.  4.1 awk - Pattern scanning and processing language                    323
  23297.  
  23298.  
  23299.  
  23300.  
  23301.  
  23302.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23303.  
  23304.  A string value shall be considered to be a _n_u_m_e_r_i_c _s_t_r_i_n_g in the
  23305.  following case:
  23306.  
  23307.      (1)  Any leading and trailing <blank>_s shall be ignored.
  23308.  
  23309.      (2)  If the first unignored character is a + or -, it shall be
  23310.           ignored.
  23311.  
  23312.      (3)  If the remaining unignored characters would be lexically
  23313.           recognized as a NUMBER token (as described by the lexical
  23314.           conventions in 4.1.7.7), the string shall be considered a
  23315.           _n_u_m_e_r_i_c _s_t_r_i_n_g.
  23316.  
  23317.  If a - character is ignored in the above steps, the numeric value of the
  23318.  _n_u_m_e_r_i_c _s_t_r_i_n_g shall be the negation of the numeric value of the
  23319.  recognized NUMBER token.  Otherwise the numeric value of the _n_u_m_e_r_i_c
  23320.  _s_t_r_i_n_g shall be the numeric value of the recognized NUMBER token.
  23321.  Whether or not a string is a _n_u_m_e_r_i_c _s_t_r_i_n_g shall be relevant only in
  23322.  contexts where that term is used in this clause.
  23323.  
  23324.  When an expression is used in a Boolean context (the first subexpression
  23325.  of a conditional expression, an expression operated on by logical NOT,
  23326.  logical AND, or logical OR, the second expression of a for statement, the
  23327.  expression of an if statement, or the expression of a while statement),
  23328.  if it has a numeric value, a value of zero shall be treated as false and
  23329.  any other value shall be treated as true.  Otherwise, a string value of
  23330.  the null string shall be treated as false and any other value shall be
  23331.  treated as true.
  23332.  
  23333.  All arithmetic shall follow the semantics of floating point arithmetic as
  23334.  specified by the C Standard {7}; see 2.9.2.
  23335.  
  23336.  The value of the expression
  23337.  
  23338.        _e_x_p_r_1 ^ _e_x_p_r_2
  23339.  
  23340.  shall be equivalent to the value returned by the C Standard {7} function
  23341.  call
  23342.  
  23343.        _p_o_w(_e_x_p_r_1, _e_x_p_r_2)
  23344.  
  23345.  The expression
  23346.  
  23347.        _l_v_a_l_u_e ^= _e_x_p_r
  23348.  
  23349.  shall be equivalent to the C Standard {7} expression
  23350.  
  23351.        _l_v_a_l_u_e = _p_o_w(_l_v_a_l_u_e, _e_x_p_r)
  23352.  
  23353.  
  23354.  
  23355.                Copyright c 1991 IEEE.  All rights reserved.
  23356.       This is an unapproved IEEE Standards Draft, subject to change.
  23357.  
  23358.  
  23359.  
  23360.  
  23361.  
  23362.  324                                     4 Execution Environment Utilities
  23363.  
  23364.  
  23365.  
  23366.  
  23367.  
  23368.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23369.  
  23370.  except that _l_v_a_l_u_e shall be evaluated only once.  The value of the
  23371.  expression
  23372.  
  23373.        _e_x_p_r_1 % _e_x_p_r_2
  23374.  
  23375.  shall be equivalent to the value returned by the C Standard {7} function
  23376.  call
  23377.  
  23378.        _f_m_o_d(_e_x_p_r_1, _e_x_p_r_2)
  23379.  
  23380.  The expression
  23381.  
  23382.        _l_v_a_l_u_e %= _e_x_p_r
  23383.  
  23384.  shall be equivalent to the C Standard {7} expression
  23385.  
  23386.        _l_v_a_l_u_e = _f_m_o_d(_l_v_a_l_u_e, _e_x_p_r)
  23387.  
  23388.  except that _l_v_a_l_u_e shall be evaluated only once.
  23389.  
  23390.  Variables and fields shall be set by the assignment statement:
  23391.  
  23392.        _l_v_a_l_u_e = _e_x_p_r_e_s_s_i_o_n
  23393.  
  23394.  and the type of _e_x_p_r_e_s_s_i_o_n shall determine the resulting variable type.
  23395.  The assignment includes the arithmetic assignments (+=, -=, *=, /=, %=,
  23396.  ^=, ++, --) all of which produce a numeric result.  The left-hand side of
  23397.  an assignment and the target of increment and decrement operators can be
  23398.  one of a variable, an array with index, or a field selector.
  23399.  
  23400.  The awk language shall supply arrays that are used for storing numbers or
  23401.  strings.  Arrays need not be declared.  They shall initially be empty,
  23402.  and their sizes shall change dynamically.  The subscripts, or element
  23403.  identifiers, are strings, providing a type of associative array
  23404.  capability.  An array name followed by a subscript within square brackets
  23405.  can be used as an _l_v_a_l_u_e and thus as an expression, as described in the
  23406.  grammar (see 4.1.7.7).  Unsubscripted array names can be used in only the
  23407.  following contexts:
  23408.  
  23409.      - A parameter in a function definition or function call.
  23410.  
  23411.      - The NAME token following any use of the keyword in as specified in
  23412.        the grammar (see 4.1.7.7).  If the name used in this context is not
  23413.        an array name, the behavior is undefined.
  23414.  
  23415.  A valid array _i_n_d_e_x shall consist of one or more comma-separated
  23416.  expressions, similar to the way in which multidimensional arrays are
  23417.  indexed in some programming languages.  Because awk arrays are really one
  23418.  dimensional, such a comma-separated list shall be converted to a single
  23419.  
  23420.  
  23421.                Copyright c 1991 IEEE.  All rights reserved.
  23422.       This is an unapproved IEEE Standards Draft, subject to change.
  23423.  
  23424.  
  23425.  
  23426.  
  23427.  
  23428.  4.1 awk - Pattern scanning and processing language                    325
  23429.  
  23430.  
  23431.  
  23432.  
  23433.  
  23434.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23435.  
  23436.  string by concatenating the string values of the separate expressions,
  23437.  each separated from the other by the value of the SUBSEP variable.  Thus,
  23438.  the following two index operations shall be equivalent:
  23439.  
  23440.        _v_a_r[_e_x_p_r_1, _e_x_p_r_2, ..., _e_x_p_r_n]
  23441.        _v_a_r[_e_x_p_r_1 _S_U_B_S_E_P _e_x_p_r_2 _S_U_B_S_E_P ... SUBSEP _e_x_p_r_n]
  23442.  
  23443.  A multidimensioned _i_n_d_e_x used with the in operator shall be
  23444.  parenthesized.  The in operator, which tests for the existence of a
  23445.  particular array element, shall not cause that element to exist.  Any
  23446.  other reference to a nonexistent array element shall automatically create
  23447.  it.
  23448.  
  23449.  Comparisons (with the <, <=, !=, ==, >, and >= operators) shall be made
  23450.  numerically if both operands are numeric or if one is numeric and the
  23451.  other has a string value that is a numeric string.  Otherwise, operands    1
  23452.  shall be converted to strings as required and a string comparison shall    1
  23453.  be made using the locale-specific collation sequence.  The value of the
  23454.  comparison expression shall be 1 if the relation is true, or 0 if the
  23455.  relation is false.
  23456.  
  23457.  
  23458.  4.1.7.3  Variables and Special Variables
  23459.  
  23460.  Variables can be used in an awk program by referencing them.  With the
  23461.  exception of function parameters (see 4.1.7.6.2), they are not explicitly
  23462.  declared.  Uninitialized scalar variables and array elements have both a
  23463.  numeric value of zero and a string value of the empty string.
  23464.  
  23465.  Field variables shall be designated by a $ followed by a number or
  23466.  numerical expression.  The effect of the field number _e_x_p_r_e_s_s_i_o_n
  23467.  evaluating to anything other than a nonnegative integer is unspecified;
  23468.  uninitialized variables or string values need not be converted to numeric
  23469.  values in this context.  New field variables can be created by assigning
  23470.  a value to them.  References to nonexistent fields (i.e., fields after
  23471.  $NF), shall produce the null string.  However, assigning to a nonexistent
  23472.  field [e.g., $(NF+_2) = 5] shall increase the value of NF, create any
  23473.  intervening fields with the null string as their values, and cause the
  23474.  value of $0 to be recomputed, with the fields being separated by the
  23475.  value of OFS.  Each field variable shall have a string value when
  23476.  created.  If the string, with any occurrence of the decimal-point
  23477.  character from the current locale changed to a <period>, would be
  23478.  considered a _n_u_m_e_r_i_c _s_t_r_i_n_g (see 4.1.7.2), the field variable shall also
  23479.  have the numeric value of the _n_u_m_e_r_i_c _s_t_r_i_n_g.
  23480.  
  23481.  The implementation shall support the following other special variables
  23482.  that are set by awk:
  23483.  
  23484.  
  23485.  
  23486.  
  23487.                Copyright c 1991 IEEE.  All rights reserved.
  23488.       This is an unapproved IEEE Standards Draft, subject to change.
  23489.  
  23490.  
  23491.  
  23492.  
  23493.  
  23494.  326                                     4 Execution Environment Utilities
  23495.  
  23496.  
  23497.  
  23498.  
  23499.  
  23500.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23501.  
  23502.     ARGC        The number of elements in the ARGV array.
  23503.  
  23504.     ARGV        An array of command line arguments, excluding options and
  23505.                 the _p_r_o_g_r_a_m argument, numbered from zero to ARGC-_1.
  23506.  
  23507.                 The arguments in ARGV can be modified or added to; ARGC
  23508.                 can be altered.  As each input file ends, awk shall treat
  23509.                 the next nonnull element of ARGV, up through the current
  23510.                 value of ARGC-_1, as the name of the next input file.
  23511.                 Thus, setting an element of ARGV to null means that it
  23512.                 shall not be treated as an input file.  The name '-' shall
  23513.                 indicate the standard input.  If an argument matches the
  23514.                 format of an _a_s_s_i_g_n_m_e_n_t operand, this argument shall be
  23515.                 treated as an assignment rather than a _f_i_l_e argument.
  23516.  
  23517.     CONVFMT     The printf format for converting numbers to strings
  23518.                 (except for output statements, where OFMT is used); "%.6g"
  23519.                 by default.
  23520.  
  23521.     ENVIRON     The variable ENVIRON is an array representing the value of
  23522.                 the environment, as described in POSIX.1 {8} 2.7.  The
  23523.                 indices of the array shall be strings consisting of the
  23524.                 names of the environment variables, and the value of each
  23525.                 array element shall be a string consisting of the value of
  23526.                 that variable.  If the value of an environment variable is
  23527.                 considered a _n_u_m_e_r_i_c _s_t_r_i_n_g (see 4.1.7.2), the array
  23528.                 element shall also have its numeric value.
  23529.  
  23530.                 In all cases where the behavior of awk is affected by
  23531.                 environment variables [including the environment of any
  23532.                 command(s) that awk executes via the system function or
  23533.                 via pipeline redirections with the print statement, the
  23534.                 printf statement, or the getline function], the
  23535.                 environment used shall be the environment at the time awk
  23536.                 began executing; it is implementation defined whether any   1
  23537.                 modification of ENVIRON affects this environment.           1
  23538.  
  23539.     FILENAME    A pathname of the current input file.  Inside a BEGIN
  23540.                 action the value is undefined.  Inside an END action the
  23541.                 value is the name of the last input file processed.
  23542.  
  23543.     FNR         The ordinal number of the current record in the current
  23544.                 file.  Inside a BEGIN action the value is zero.  Inside an
  23545.                 END action the value is the number of the last record
  23546.                 processed in the last file processed.
  23547.  
  23548.     FS          Input field separator regular expression; <space> by
  23549.                 default.
  23550.  
  23551.  
  23552.  
  23553.                Copyright c 1991 IEEE.  All rights reserved.
  23554.       This is an unapproved IEEE Standards Draft, subject to change.
  23555.  
  23556.  
  23557.  
  23558.  
  23559.  
  23560.  4.1 awk - Pattern scanning and processing language                    327
  23561.  
  23562.  
  23563.  
  23564.  
  23565.  
  23566.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23567.  
  23568.     NF          The number of fields in the current record.  Inside a
  23569.                 BEGIN action, the use of NF is undefined unless a getline
  23570.                 function without a _v_a_r argument is executed previously.
  23571.                 Inside an END action, NF shall retain the value it had for
  23572.                 the last record read, unless a subsequent, redirected,
  23573.                 getline function without a _v_a_r argument is performed prior
  23574.                 to entering the END action.
  23575.  
  23576.     NR          The ordinal number of the current record from the start of
  23577.                 input.  Inside a BEGIN action the value is zero.  Inside
  23578.                 an END action the value is the number of the last record
  23579.                 processed.
  23580.  
  23581.     OFMT        The printf format for converting numbers to strings in
  23582.                 output statements (see 4.1.7.6.1); "%.6g" by default.  The  2
  23583.                 result of the conversion is unspecified if the value of     2
  23584.                 OFMT is not a floating-point format specification.          2
  23585.  
  23586.     OFS         The print statement output field separation; <space> by
  23587.                 default.
  23588.  
  23589.     ORS         The print statement output record separator; <newline> by
  23590.                 default.
  23591.  
  23592.     RLENGTH     The length of the string matched by the match function.
  23593.  
  23594.     RS          The first character of the string value of RS is the input
  23595.                 record separator; <newline> by default.  If RS contains
  23596.                 more than one character, the results are unspecified.  If
  23597.                 RS is null, then records are separated by sequences of one
  23598.                 or more blank lines, leading or trailing blank lines do
  23599.                 not result in empty records at the beginning or end of the
  23600.                 input, and <newline> is always a field separator, no
  23601.                 matter what the value of FS is.
  23602.  
  23603.     RSTART      The starting position of the string matched by the match
  23604.                 function, numbering from 1.  This is always equivalent to
  23605.                 the return value of the match function.
  23606.  
  23607.     SUBSEP      The subscript separator string for multidimensional
  23608.                 arrays; the default value is implementation defined.
  23609.  
  23610.  
  23611.  4.1.7.4  Regular Expressions
  23612.  
  23613.  The awk utility shall make use of the extended regular expression
  23614.  notation (see 2.8.4) except that it shall allow the use of C-language
  23615.  conventions for escaping special characters within the EREs, as specified
  23616.  in Table 2-15 and Table 4-2; these escape sequences shall be recognized    1
  23617.  both inside and outside bracket expressions.  Note that records need not   1
  23618.  
  23619.                Copyright c 1991 IEEE.  All rights reserved.
  23620.       This is an unapproved IEEE Standards Draft, subject to change.
  23621.  
  23622.  
  23623.  
  23624.  
  23625.  
  23626.  328                                     4 Execution Environment Utilities
  23627.  
  23628.  
  23629.  
  23630.  
  23631.  
  23632.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23633.  
  23634.  be separated by <newline>s and string constants can contain <newline>s,    1
  23635.  so even the \n sequence is valid in awk EREs.  Using a slash character     1
  23636.  within the regular expression requires the escaping shown in Table 4-2.    1
  23637.  
  23638.  A regular expression can be matched against a specific field or string by
  23639.  using one of the two regular expression matching operators,   and ! .
  23640.  These operators shall interpret their right-hand operand as ~a regul~ar
  23641.  expression and their left-hand operand as a string.  If the regular
  23642.  expression matches the string, the   expression shall evaluate to a value
  23643.  of 1, and the !  expression shall e~valuate to a value of 0.  (The regular
  23644.  expression matc~hing operation is as defined in 2.8.1.2, where a match
  23645.  occurs on any part of the string unless the regular expression is limited
  23646.  with the circumflex or dollar-sign special characters.)  If the regular
  23647.  expression does not match the string, the   expression shall evaluate to
  23648.  a value of 0, and the !  expression shall ~evaluate to a value of 1.  If
  23649.  the right-hand operand ~is any expression other than the lexical token
  23650.  ERE, the string value of the expression shall be interpreted as an
  23651.  extended regular expression, including the escape conventions described
  23652.  above.  Note that these same escape conventions also shall be applied in
  23653.  the determining the value of a string literal (the lexical token STRING),
  23654.  and thus shall be applied a second time when a string literal is used in
  23655.  this context.
  23656.  
  23657.  When an ERE token appears as an expression in any context other than as
  23658.  the right-hand of the   or !  operator or as one of the built-in function
  23659.  arguments described be~low, t~he value of the resulting expression shall be
  23660.  the equivalent of
  23661.  
  23662.        $0   /_e_r_e/
  23663.           ~
  23664.  The _E_R_E argument to the gsub, match, sub functions, and the _f_s argument
  23665.  to the split function (see 4.1.7.6.2) shall be interpreted as extended
  23666.  regular expressions.  These can be either ERE tokens or arbitrary
  23667.  expressions, and shall be interpreted in the same manner as the right-
  23668.  hand side of the   or !  operator.
  23669.                   ~     ~
  23670.  An extended regular expression can be used to separate fields by using
  23671.  the -F _E_R_E option or by assigning a string containing the expression to
  23672.  the built-in variable FS.  The default value of the FS variable shall be
  23673.  a single <space> character.  The following describes FS behavior:
  23674.  
  23675.      (1)  If FS is a single character:
  23676.  
  23677.            (a)  If FS is <space>, skip leading and trailing <blank>_s;
  23678.                 fields shall be delimited by sets of one or more <blank>_s.
  23679.  
  23680.            (b)  Otherwise, if FS is any other character _c, fields shall be
  23681.                 delimited by each single occurrence of _c.
  23682.  
  23683.  
  23684.  
  23685.                Copyright c 1991 IEEE.  All rights reserved.
  23686.       This is an unapproved IEEE Standards Draft, subject to change.
  23687.  
  23688.  
  23689.  
  23690.  
  23691.  
  23692.  4.1 awk - Pattern scanning and processing language                    329
  23693.  
  23694.  
  23695.  
  23696.  
  23697.  
  23698.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23699.  
  23700.      (2)  Otherwise, the string value of FS shall be considered to be an
  23701.           extended regular expression.  Each occurrence of a sequence
  23702.           matching the extended regular expression shall delimit fields.
  23703.  
  23704.  Except in the gsub, match, split, and sub built-in functions, regular
  23705.  expression matching shall be based on input records; i.e., record
  23706.  separator characters (the first character of the value of the variable
  23707.  RS, <newline> by default) cannot be embedded in the expression, and no
  23708.  expression shall match the record separator character.  If the record
  23709.  separator is not <newline>, <newline> characters embedded in the
  23710.  expression can be matched.  In those four built-in functions, regular
  23711.  expression matching shall be based on text strings; i.e., any character
  23712.  (including <newline> and the record separator) can be embedded in the
  23713.  pattern and an appropriate pattern shall match any character.  However,
  23714.  in all awk regular expression matching, the use of one or more NUL
  23715.  characters in the pattern, input record, or text string produces
  23716.  undefined results.
  23717.  
  23718.  
  23719.  4.1.7.5  Patterns
  23720.  
  23721.  A _p_a_t_t_e_r_n is any valid _e_x_p_r_e_s_s_i_o_n, a range specified by two expressions
  23722.  separated by comma, or one of the two special patterns BEGIN or END.
  23723.  
  23724.  4.1.7.5.1  Special Patterns
  23725.  
  23726.  The awk utility shall recognize two special patterns, BEGIN and END.
  23727.  Each BEGIN pattern shall be matched once and its associated action
  23728.  executed before the first record of input is read [except possibly by use
  23729.  of the getline function (see 4.1.7.6.2) in a prior BEGIN action] and
  23730.  before command line assignment is done.  Each END pattern shall be
  23731.  matched once and its associated action executed after the last record of
  23732.  input has been read.  These two patterns shall have associated actions.
  23733.  
  23734.  BEGIN and END shall not combine with other patterns.  Multiple BEGIN and
  23735.  END patterns shall be allowed.  The actions associated with the BEGIN
  23736.  patterns shall be executed in the order specified in the program, as are
  23737.  the END actions.  An END pattern can precede a BEGIN pattern in a
  23738.  program.
  23739.  
  23740.  If an awk program consists of only actions with the pattern BEGIN, and
  23741.  the BEGIN action contains no getline function, awk shall exit without
  23742.  reading its input when the last statement in the last BEGIN action is
  23743.  executed.  If an awk program consists of only actions with the pattern
  23744.  END or only actions with the patterns BEGIN and END, the input shall be
  23745.  read before the statements in the END action(s) are executed.
  23746.  
  23747.  
  23748.  
  23749.  
  23750.  
  23751.                Copyright c 1991 IEEE.  All rights reserved.
  23752.       This is an unapproved IEEE Standards Draft, subject to change.
  23753.  
  23754.  
  23755.  
  23756.  
  23757.  
  23758.  330                                     4 Execution Environment Utilities
  23759.  
  23760.  
  23761.  
  23762.  
  23763.  
  23764.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23765.  
  23766.  4.1.7.5.2  Expression Patterns
  23767.  
  23768.  An expression pattern shall be evaluated as if it were an expression in a  1
  23769.  Boolean context.  If the result is true, the pattern shall be considered   1
  23770.  to match, and the associated action (if any) shall be executed.  If the    1
  23771.  result is false, the action shall not be executed.                         1
  23772.  
  23773.  4.1.7.5.3  Pattern Ranges
  23774.  
  23775.  A pattern range consists of two expressions separated by a comma; in this
  23776.  case, the action shall be performed for all records between a match of
  23777.  the first expression and the following match of the second expression,
  23778.  inclusive.  At this point, the pattern range can be repeated starting at
  23779.  input records subsequent to the end of the matched range.
  23780.  
  23781.  
  23782.  4.1.7.6  Actions
  23783.  
  23784.  An action is a sequence of statements as shown in the grammar in 4.1.7.7.
  23785.  Any single statement can be replaced by a statement list enclosed in
  23786.  braces.  The statements in a statement list shall be separated by
  23787.  <newline>s or semicolons, and shall be executed sequentially in the order
  23788.  that they appear.
  23789.  
  23790.  The _e_x_p_r_e_s_s_i_o_n acting as the conditional in an if statement shall be
  23791.  evaluated and if it is nonzero or nonnull, the following _s_t_a_t_e_m_e_n_t shall
  23792.  be executed; otherwise, if else is present, the statement following the
  23793.  else shall be executed.
  23794.  
  23795.  The if, while, do ...  while, for, break, and continue statements are
  23796.  based on the C Standard {7} (see 2.9.2), except that the Boolean
  23797.  expressions shall be treated as described in 4.1.7.2, and except in the
  23798.  case of
  23799.  
  23800.        for (_v_a_r_i_a_b_l_e _i_n _a_r_r_a_y)
  23801.  
  23802.  which shall iterate, assigning each _i_n_d_e_x of _a_r_r_a_y to _v_a_r_i_a_b_l_e in an
  23803.  unspecified order.  The results of adding new elements to _a_r_r_a_y within
  23804.  such a for loop are undefined.  If a break or continue statement occurs
  23805.  outside of a loop, the behavior is undefined.
  23806.  
  23807.  The delete statement shall remove an individual array element.  Thus, the
  23808.  following code shall delete an entire array:
  23809.  
  23810.        for (index in array)
  23811.                delete array[index]
  23812.  
  23813.  The next statement shall cause all further processing of the current
  23814.  input record to be abandoned.  The behavior is undefined if a next
  23815.  statement appears or is invoked in a BEGIN or END action.
  23816.  
  23817.                Copyright c 1991 IEEE.  All rights reserved.
  23818.       This is an unapproved IEEE Standards Draft, subject to change.
  23819.  
  23820.  
  23821.  
  23822.  
  23823.  
  23824.  4.1 awk - Pattern scanning and processing language                    331
  23825.  
  23826.  
  23827.  
  23828.  
  23829.  
  23830.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23831.  
  23832.  The exit statement shall invoke all END actions in the order in which
  23833.  they occur in the program source and then terminate the program without
  23834.  reading further input.  An exit statement inside an END action shall
  23835.  terminate the program without further execution of END actions.  If an
  23836.  expression is specified in an exit statement, its numeric value shall be
  23837.  the exit status of awk, unless subsequent errors are encountered or a
  23838.  subsequent exit statement with an expression is executed.
  23839.  
  23840.  4.1.7.6.1  Output Statements
  23841.  
  23842.  Both print and printf statements shall write to standard output by
  23843.  default.  The output shall be written to the location specified by
  23844.  _o_u_t_p_u_t__r_e_d_i_r_e_c_t_i_o_n if one is supplied, as follows:
  23845.  
  23846.        > _e_x_p_r_e_s_s_i_o_n
  23847.        >> _e_x_p_r_e_s_s_i_o_n
  23848.        | _e_x_p_r_e_s_s_i_o_n
  23849.  
  23850.  In all cases, the _e_x_p_r_e_s_s_i_o_n shall be evaluated to produce a string that
  23851.  is used as a full pathname to write into (for > or >>) or as a command to
  23852.  be executed (for |).  Using the first two forms, if the file of that name
  23853.  is not currently open, it shall be opened, creating it if necessary, and
  23854.  using the first form, truncating the file.  The output then shall be
  23855.  appended to the file.  As long as the file remains open, subsequent calls
  23856.  in which _e_x_p_r_e_s_s_i_o_n evaluates to the same string value simply shall
  23857.  append output to the file.  The file remains open until the close
  23858.  function (see 4.1.7.6.2).  is called with an expression that evaluates to
  23859.  the same string value.
  23860.  
  23861.  The third form shall write output onto a stream piped to the input of a
  23862.  command.  The stream shall be created if no stream is currently open with
  23863.  the value of _e_x_p_r_e_s_s_i_o_n as its command name.  The stream created shall be
  23864.  equivalent to one created by a call to the _p_o_p_e_n() function (see B.3.2)
  23865.  with the value of _e_x_p_r_e_s_s_i_o_n as the _c_o_m_m_a_n_d argument and a value of "w"
  23866.  as the _m_o_d_e argument.  As long as the stream remains open, subsequent
  23867.  calls in which _e_x_p_r_e_s_s_i_o_n evaluates to the same string value shall write
  23868.  output to the existing stream.  The stream shall remain open until the
  23869.  close function (see 4.1.7.6.2) is called with an expression that
  23870.  evaluates to the same string value.  At that time, the stream shall be
  23871.  closed as if by a call to the _p_c_l_o_s_e() function (see B.3.2).
  23872.  
  23873.  As described in detail by the grammar in 4.1.7.7, these output statements
  23874.  shall take a comma-separated list of _e_x_p_r_e_s_s_i_o_ns referred in the grammar
  23875.  by the nonterminal symbols expr_list, print_expr_list, or
  23876.  print_expr_list_opt.  This list is referred to here as the _e_x_p_r_e_s_s_i_o_n
  23877.  _l_i_s_t, and each member is referred to as an _e_x_p_r_e_s_s_i_o_n _a_r_g_u_m_e_n_t.
  23878.  
  23879.  The print statement shall write the value of each expression argument
  23880.  onto the indicated output stream separated by the current output field
  23881.  
  23882.  
  23883.                Copyright c 1991 IEEE.  All rights reserved.
  23884.       This is an unapproved IEEE Standards Draft, subject to change.
  23885.  
  23886.  
  23887.  
  23888.  
  23889.  
  23890.  332                                     4 Execution Environment Utilities
  23891.  
  23892.  
  23893.  
  23894.  
  23895.  
  23896.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  23897.  
  23898.  separator (see variable OFS above), and terminated by the output record
  23899.  separator (see variable ORS above).  All expression arguments shall be
  23900.  taken as strings, being converted if necessary; this conversion shall be   1
  23901.  as described in 4.1.7.2, with the exception that the printf format in      1
  23902.  OFMT shall be used instead of the value in CONVFMT.  An empty expression   1
  23903.  list shall stand for the whole input record ($0).
  23904.  
  23905.  The printf statement shall produce output based on a notation similar to
  23906.  the File Format Notation used to describe file formats in this standard
  23907.  (see 2.12).  Output shall be produced as specified with the first
  23908.  expression argument as the string <_f_o_r_m_a_t> and subsequent expression
  23909.  arguments as the strings <_a_r_g_1> through <_a_r_g_n>, with the following
  23910.  exceptions:
  23911.  
  23912.      (1)  The _f_o_r_m_a_t shall be an actual character string rather than a
  23913.           graphical representation.  Therefore, it cannot contain empty
  23914.           character positions.  The <space> character in the _f_o_r_m_a_t
  23915.           string, in any context other than a _f_l_a_g of a conversion
  23916.           specification, shall be treated as an ordinary character that is
  23917.           copied to the output.
  23918.  
  23919.      (2)  If the character set contains a W character and that character
  23920.           appears in the _f_o_r_m_a_t string, it shall be treated as an ordinary
  23921.           character that is copied to the output.
  23922.  
  23923.      (3)  The _e_s_c_a_p_e _s_e_q_u_e_n_c_e_s beginning with a backslash character shall
  23924.           be treated as sequences of ordinary characters that are copied
  23925.           to the output.  (Note that these same sequences shall be
  23926.           interpreted lexically by awk when they appear in literal
  23927.           strings, but they shall not be treated specially by the printf
  23928.           statement).
  23929.  
  23930.      (4)  A _f_i_e_l_d _w_i_d_t_h or _p_r_e_c_i_s_i_o_n can be specified as the * character
  23931.           instead of a digit string.  In this case the next argument from
  23932.           the expression list shall be fetched and its numeric value taken
  23933.           as the field width or precision.
  23934.  
  23935.      (5)  The implementation shall not precede or follow output from the d
  23936.           or u conversion specifications with <blank>_s not specified by
  23937.           the _f_o_r_m_a_t string.
  23938.  
  23939.      (6)  The implementation shall not precede output from the o
  23940.           conversion specification with leading zeroes not specified by
  23941.           the _f_o_r_m_a_t string.
  23942.  
  23943.      (7)  For the c conversion specification:  if the argument has a
  23944.           numeric value, the character whose encoding is that value shall
  23945.           be output.  If the value is zero or is not the encoding of any
  23946.           character in the character set, the behavior is undefined.  If
  23947.  
  23948.  
  23949.                Copyright c 1991 IEEE.  All rights reserved.
  23950.       This is an unapproved IEEE Standards Draft, subject to change.
  23951.  
  23952.  
  23953.  
  23954.  
  23955.  
  23956.  4.1 awk - Pattern scanning and processing language                    333
  23957.  
  23958.  
  23959.  
  23960.  
  23961.  
  23962.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  23963.  
  23964.           the argument does not have a numeric value, the first character
  23965.           of the string value shall be output; if the string does not
  23966.           contain any characters the behavior is undefined.
  23967.  
  23968.      (8)  For each conversion specification that consumes an argument, the
  23969.           next expression argument shall be evaluated.  With the exception
  23970.           of the c conversion, the value shall be converted (according to
  23971.           the rules specified in 4.1.7.2) to the appropriate type for the
  23972.           conversion specification.
  23973.  
  23974.      (9)  If there are insufficient expression arguments to satisfy all
  23975.           the conversion specifications in the _f_o_r_m_a_t string, the behavior
  23976.           is undefined.
  23977.  
  23978.     (10)  If any character sequence in the _f_o_r_m_a_t string begins with a %
  23979.           character, but does not form a valid conversion specification,
  23980.           the behavior is unspecified.
  23981.  
  23982.  Both print and printf can output at least {LINE_MAX} bytes.
  23983.  
  23984.  4.1.7.6.2  Functions
  23985.  
  23986.  The awk language has a variety of built-in functions: arithmetic, string,
  23987.  input/output, and general.
  23988.  
  23989.  4.1.7.6.2.1  _A_r_i_t_h_m_e_t_i_c__F_u_n_c_t_i_o_n_s
  23990.  
  23991.  The arithmetic functions, except for int, shall be based on the
  23992.  C Standard {7}; see 2.9.2.  The behavior is undefined in cases where the
  23993.  C Standard {7} specifies that an error be returned or that the behavior
  23994.  is undefined.
  23995.  
  23996.     atan2(_y,_x)         Return arctangent of _y/_x.
  23997.  
  23998.     cos(_x)             _R_e_t_u_r_n _c_o_s_i_n_e _o_f _x, _w_h_e_r_e _x _i_s _i_n _r_a_d_i_a_n_s.
  23999.  
  24000.     _s_i_n(_x)             _R_e_t_u_r_n _s_i_n_e _o_f _x, _w_h_e_r_e _x _i_s _i_n _r_a_d_i_a_n_s.
  24001.  
  24002.     _e_x_p(_x)             _R_e_t_u_r_n _t_h_e _e_x_p_o_n_e_n_t_i_a_l _f_u_n_c_t_i_o_n _o_f _x.
  24003.  
  24004.     _l_o_g(_x)             _R_e_t_u_r_n _t_h_e _n_a_t_u_r_a_l _l_o_g_a_r_i_t_h_m _o_f _x.
  24005.  
  24006.     _s_q_r_t(_x)            _R_e_t_u_r_n _t_h_e _s_q_u_a_r_e _r_o_o_t _o_f _x.
  24007.  
  24008.     _i_n_t(_x)             _T_r_u_n_c_a_t_e _i_t_s _a_r_g_u_m_e_n_t _t_o _a_n _i_n_t_e_g_e_r.  _I_t _s_h_a_l_l _b_e
  24009.                        _t_r_u_n_c_a_t_e_d _t_o_w_a_r_d _0 _w_h_e_n _x > 0.
  24010.  
  24011.     rand()             _R_e_t_u_r_n _a _r_a_n_d_o_m _n_u_m_b_e_r _n, _s_u_c_h _t_h_a_t _0 _< _n < _1.
  24012.  
  24013.  
  24014.  
  24015.                Copyright c 1991 IEEE.  All rights reserved.
  24016.       This is an unapproved IEEE Standards Draft, subject to change.
  24017.  
  24018.  
  24019.  
  24020.  
  24021.  
  24022.  334                                     4 Execution Environment Utilities
  24023.  
  24024.  
  24025.  
  24026.  
  24027.  
  24028.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24029.  
  24030.     _s_r_a_n_d([expr])      Set the seed value for rand to _e_x_p_r or use the time
  24031.                        of day if _e_x_p_r is omitted.  The previous seed value
  24032.                        shall be returned.
  24033.  
  24034.  4.1.7.6.2.2  _S_t_r_i_n_g__F_u_n_c_t_i_o_n_s
  24035.  
  24036.  The string functions are:
  24037.  
  24038.     gsub(_e_r_e, _r_e_p_l[,_i_n])
  24039.                        Behave like sub (see below), except that it shall
  24040.                        replace all occurrences of the regular expression
  24041.                        (like the ed utility global substitute) in $0 or in
  24042.                        the _i_n argument, when specified.
  24043.  
  24044.     index(_s, _t)        Return the position, in characters, numbering from
  24045.                        1, in string _s where string _t first occurs, or zero
  24046.                        if it does not occur at all.
  24047.  
  24048.     length([_s])        Return the length, in characters, of its argument
  24049.                        taken as a string, or of the whole record, $0, if
  24050.                        there is no argument.
  24051.  
  24052.     match(_s, _e_r_e)      Return the position, in characters, numbering from
  24053.                        1, in string _s where the extended regular
  24054.                        expression _E_R_E occurs, or zero if it does not occur
  24055.                        at all.  RSTART shall be set to the starting
  24056.                        position (which is the same as the returned value),
  24057.                        zero if no match is found; RLENGTH shall be set to
  24058.                        the length of the matched string, -1 if no match is
  24059.                        found.
  24060.  
  24061.     split(_s, _a[,_f_s])   Split the string _s into array elements _a[1], _a[2],
  24062.                        ... , _a[_n], and returns _n.  The separation shall be
  24063.                        done with the extended regular expression _f_s or
  24064.                        with the field separator FS if _f_s is not given.
  24065.                        Each array element shall have a string value when
  24066.                        created.  If the string assigned to any array
  24067.                        element, with any occurrence of the decimal-point
  24068.                        character from the current locale changed to a
  24069.                        <period>, would be considered a _n_u_m_e_r_i_c _s_t_r_i_n_g (see
  24070.                        4.1.7.2), the array element shall also have the
  24071.                        numeric value of the _n_u_m_e_r_i_c _s_t_r_i_n_g.  The effect of
  24072.                        a null string as the value of _f_s is unspecified.
  24073.  
  24074.     sprintf(_f_m_t, _e_x_p_r, _e_x_p_r, ...)
  24075.                        Format the expressions according to the printf
  24076.                        format given by _f_m_t and return the resulting
  24077.                        string.
  24078.  
  24079.  
  24080.  
  24081.                Copyright c 1991 IEEE.  All rights reserved.
  24082.       This is an unapproved IEEE Standards Draft, subject to change.
  24083.  
  24084.  
  24085.  
  24086.  
  24087.  
  24088.  4.1 awk - Pattern scanning and processing language                    335
  24089.  
  24090.  
  24091.  
  24092.  
  24093.  
  24094.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24095.  
  24096.     sub(_e_r_e, _r_e_p_l[,_i_n])
  24097.                        Substitute the string _r_e_p_l in place of the first
  24098.                        instance of the extended regular expression _E_R_E in
  24099.                        string _i_n and return the number of substitutions.
  24100.                        An ampersand (&) appearing in the string _r_e_p_l shall
  24101.                        be replaced by the string from _i_n that matches the
  24102.                        regular expression.  An ampersand preceded by a
  24103.                        backslash within _r_e_p_l shall be interpreted as a
  24104.                        literal ampersand character.  If _i_n is specified
  24105.                        and it is not an _l_v_a_l_u_e (see 4.1.7.2), the behavior
  24106.                        is undefined.  If _i_n is omitted, awk shall
  24107.                        substitute in the current record ($0).
  24108.  
  24109.     substr(_s, _m[,_n])
  24110.                        Return the at most _n-character substring of _s that
  24111.                        begins at position _m, numbering from 1.  If _n is
  24112.                        missing, the length of the substring shall be
  24113.                        limited by the length of the string _s.
  24114.  
  24115.     tolower(_s)         Return a string based on the string _s.  Each
  24116.                        character in _s that is an uppercase letter
  24117.                        specified to have a tolower mapping by the LC_CTYPE
  24118.                        category of the current locale shall be replaced in
  24119.                        the returned string by the lowercase letter
  24120.                        specified by the mapping.  Other characters in _s
  24121.                        shall be unchanged in the returned string.
  24122.  
  24123.     toupper(_s)         Return a string based on the string _s.  Each
  24124.                        character in _s that is a lowercase letter specified
  24125.                        to have a toupper mapping by the LC_CTYPE category
  24126.                        of the current locale shall be replaced in the
  24127.                        returned string by the uppercase letter specified
  24128.                        by the mapping.  Other characters in _s shall be
  24129.                        unchanged in the returned string.
  24130.  
  24131.  All of the preceding functions that take _E_R_E as a parameter expect a
  24132.  pattern or a string valued expression that is a regular expression as
  24133.  defined in 4.1.7.4.
  24134.  
  24135.  4.1.7.6.2.3  _I_n_p_u_t_/_O_u_t_p_u_t__a_n_d__G_e_n_e_r_a_l__F_u_n_c_t_i_o_n_s
  24136.  
  24137.  The input/output and general functions are:
  24138.  
  24139.     close(_e_x_p_r_e_s_s_i_o_n)  Close the file or pipe opened by a print or printf
  24140.                        statement or a call to getline with the same
  24141.                        string-valued _e_x_p_r_e_s_s_i_o_n.  The limit on the number
  24142.                        of open _e_x_p_r_e_s_s_i_o_n arguments is implementation
  24143.                        defined.  If the close was successful, the function
  24144.                        shall return zero; otherwise, it shall return
  24145.  
  24146.  
  24147.                Copyright c 1991 IEEE.  All rights reserved.
  24148.       This is an unapproved IEEE Standards Draft, subject to change.
  24149.  
  24150.  
  24151.  
  24152.  
  24153.  
  24154.  336                                     4 Execution Environment Utilities
  24155.  
  24156.  
  24157.  
  24158.  
  24159.  
  24160.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24161.  
  24162.                        nonzero.
  24163.  
  24164.     _e_x_p_r_e_s_s_i_o_n | _g_e_t_l_i_n_e [_v_a_r]
  24165.                        Read a record of input from a stream piped from the
  24166.                        output of a command.  The stream shall be created
  24167.                        if no stream is currently open with the value of
  24168.                        _e_x_p_r_e_s_s_i_o_n as its command name.  The stream created
  24169.                        shall be equivalent to one created by a call to the
  24170.                        _p_o_p_e_n() function with the value of _e_x_p_r_e_s_s_i_o_n as
  24171.                        the _c_o_m_m_a_n_d argument and a value of "r" as the _m_o_d_e
  24172.                        argument.  As long as the stream remains open,
  24173.                        subsequent calls in which _e_x_p_r_e_s_s_i_o_n evaluates to
  24174.                        the same string value shall read subsequent records
  24175.                        from the file.  The stream shall remain open until
  24176.                        the close function is called with an expression
  24177.                        that evaluates to the same string value.  At that
  24178.                        time, the stream shall be closed as if by a call to
  24179.                        the _p_c_l_o_s_e() function.  If _v_a_r is missing, $0 and
  24180.                        NF shall be set; otherwise, _v_a_r shall be set.
  24181.  
  24182.     getline            Set $0 to the next input record from the current
  24183.                        input file.  This form of getline shall set the NF,
  24184.                        NR, and FNR variables.
  24185.  
  24186.     getline _v_a_r        Set variable _v_a_r to the next input record from the
  24187.                        current input file.  This form of getline shall set
  24188.                        the FNR and NR variables.
  24189.  
  24190.     getline [_v_a_r] < _e_x_p_r_e_s_s_i_o_n
  24191.                        Read the next record of input from a named file.
  24192.                        The _e_x_p_r_e_s_s_i_o_n shall be evaluated to produce a
  24193.                        string that is used as a full pathname.  If the
  24194.                        file of that name is not currently open, it shall
  24195.                        be opened.  As long as the stream remains open,
  24196.                        subsequent calls in which _e_x_p_r_e_s_s_i_o_n evaluates to
  24197.                        the same string value shall read subsequent records
  24198.                        from the file.  The file shall remain open until
  24199.                        the close function is called with an expression
  24200.                        that evaluates to the same string value.  If _v_a_r is
  24201.                        missing, $0 and NF shall be set; otherwise, _v_a_r
  24202.                        shall be set.
  24203.  
  24204.     system(_e_x_p_r_e_s_s_i_o_n)
  24205.                        Execute the command given by _e_x_p_r_e_s_s_i_o_n in a manner
  24206.                        equivalent to the _s_y_s_t_e_m() function [see B.3.1] and
  24207.                        return the exit status of the command.
  24208.  
  24209.  All forms of getline shall return 1 for successful input, zero for end of
  24210.  file, and -1 for an error.
  24211.  
  24212.  
  24213.                Copyright c 1991 IEEE.  All rights reserved.
  24214.       This is an unapproved IEEE Standards Draft, subject to change.
  24215.  
  24216.  
  24217.  
  24218.  
  24219.  
  24220.  4.1 awk - Pattern scanning and processing language                    337
  24221.  
  24222.  
  24223.  
  24224.  
  24225.  
  24226.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24227.  
  24228.  4.1.7.6.2.4  _U_s_e_r_-_D_e_f_i_n_e_d__F_u_n_c_t_i_o_n_s
  24229.  
  24230.  The awk language also shall provide user-defined functions.  Such
  24231.  functions can be defined as:
  24232.  
  24233.        _f_u_n_c_t_i_o_n _n_a_m_e(_a_r_g_s,...) {  _s_t_a_t_e_m_e_n_t_s }
  24234.  
  24235.  A function can be referred to anywhere in an awk program; in particular,
  24236.  its use can precede its definition.  The scope of a function shall be
  24237.  global.
  24238.  
  24239.  Function arguments can be either scalars or arrays; the behavior is
  24240.  undefined if an array name is passed as an argument that the function
  24241.  uses as a scalar, or if a scalar expression is passed as an argument that
  24242.  the function uses as an array.  Function arguments shall be passed by
  24243.  value if scalar and by reference if array name.  Argument names shall be
  24244.  local to the function; all other variable names shall be global.  The
  24245.  same name shall not be used as both an argument name and as the name of a
  24246.  function or a special awk variable.  The same name shall not be used both
  24247.  as a variable name with global scope and as the name of a function.  The
  24248.  same name shall not be used within the same scope both as a scalar
  24249.  variable and as an array.
  24250.  
  24251.  The number of parameters in the function definition need not match the
  24252.  number of parameters in the function call.  Excess formal parameters can
  24253.  be used as local variables.  If fewer arguments are supplied in a          1
  24254.  function call than are in the function definition, the extra parameters    1
  24255.  that are used in the function body as scalars shall be initialized with a  1
  24256.  string value of the null string and a numeric value of zero, and the       1
  24257.  extra parameters that are used in the function body as arrays shall be     1
  24258.  initialized as empty arrays.  If more arguments are supplied in a          1
  24259.  function call than are in the function definition, the behavior is
  24260.  undefined.
  24261.  
  24262.  When invoking a function, no white space can be placed between the
  24263.  function name and the opening parenthesis.  The implementation shall       1
  24264.  permit function calls to be nested, and for recursive calls to be made     1
  24265.  upon functions.  Upon return from any nested or recursive function call,
  24266.  the values of all of the calling function's parameters shall be
  24267.  unchanged, except for array parameters passed by reference.  The return
  24268.  statement can be used to return a value.  If a return statement appears
  24269.  outside of a function definition, the behavior is undefined.
  24270.  
  24271.  In the function definition, <newline>s shall be optional before the
  24272.  opening brace and after the closing brace.  Function definitions can
  24273.  appear anywhere in the program where a _p_a_t_t_e_r_n-_a_c_t_i_o_n pair is allowed.
  24274.  
  24275.  
  24276.  
  24277.  
  24278.  
  24279.                Copyright c 1991 IEEE.  All rights reserved.
  24280.       This is an unapproved IEEE Standards Draft, subject to change.
  24281.  
  24282.  
  24283.  
  24284.  
  24285.  
  24286.  338                                     4 Execution Environment Utilities
  24287.  
  24288.  
  24289.  
  24290.  
  24291.  
  24292.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24293.  
  24294.  _4._1._7._7  awk _G_r_a_m_m_a_r
  24295.  
  24296.  The grammar in this subclause and the lexical conventions in the
  24297.  following subclause shall together describe the syntax for awk programs.
  24298.  The general conventions for this style of grammar are described in 2.1.2.
  24299.  A valid program can be represented as the nonterminal symbol _p_r_o_g_r_a_m in
  24300.  the grammar.  Any discrepancies found between this grammar and other
  24301.  descriptions in this clause shall be resolved in favor of this grammar.
  24302.  
  24303.  %token   NAME NUMBER STRING ERE NEWLINE
  24304.  %token   FUNC_NAME     /* name followed by '(' without white space */
  24305.  
  24306.           /* Keywords */
  24307.  %token    Begin   End
  24308.  /*       'BEGIN' 'END' */
  24309.  
  24310.  %token    Break   Continue   Delete   Do   Else
  24311.  /*       'break' 'continue' 'delete' 'do' 'else' */
  24312.  
  24313.  %token    Exit   For   Function   If   In
  24314.  /*       'exit' 'for' 'function' 'if' 'in' */
  24315.  
  24316.  %token    Next   Print   Printf   Return   While
  24317.  /*       'next' 'print' 'printf' 'return' 'while' */
  24318.  
  24319.           /* Reserved function names */
  24320.  %token   BUILTIN_FUNC_NAME      /* one token for the following:
  24321.           * atan2 cos sin exp log sqrt int rand srand
  24322.           * gsub index length match split sprintf sub substr
  24323.           * tolower toupper close system
  24324.           */
  24325.  %token   GETLINE      /* Syntactically different from other built-ins */
  24326.  
  24327.           /* Two-character tokens */
  24328.  %token   ADD_ASSIGN SUB_ASSIGN MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN POW_ASSIGN
  24329.  /*         '+='       '-='      '*='      '/='      '%='      '^=' */
  24330.  
  24331.  %token    OR  AND  NO_MATCH EQ   LE   GE   NE  INCR DECR APPEND
  24332.  /*       '||' '&&' '! '    '==' '<=' '>=' '!=' '++' '--' '>>' */
  24333.                       ~
  24334.           /* One-character tokens */
  24335.  %token   '{' '}' '(' ')' '[' ']' ',' ';'
  24336.  %token   '+' '-' '*' '%' '^' '!' '>' '<' '|' '?' ':' ' ' '$' '='
  24337.                                                        ~
  24338.  %start   program
  24339.  %%
  24340.  
  24341.  
  24342.  program:
  24343.  
  24344.  
  24345.                Copyright c 1991 IEEE.  All rights reserved.
  24346.       This is an unapproved IEEE Standards Draft, subject to change.
  24347.  
  24348.  
  24349.  
  24350.  
  24351.  
  24352.  4.1 awk - Pattern scanning and processing language                    339
  24353.  
  24354.  
  24355.  
  24356.  
  24357.  
  24358.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24359.  
  24360.          item_list
  24361.        | actionless_item_list
  24362.        ;
  24363.  
  24364.  item_list:
  24365.          newline_opt
  24366.        | actionless_item_list item terminator
  24367.        | item_list item terminator
  24368.        | item_list action terminator
  24369.        ;
  24370.  
  24371.  actionless_item_list:
  24372.          item_list pattern terminator
  24373.        | actionless_item_list pattern terminator
  24374.        ;
  24375.  
  24376.  item:
  24377.          pattern action
  24378.        | Function NAME '(' param_list_opt ')' newline_opt action
  24379.        | Function FUNC_NAME '(' param_list_opt ')' newline_opt action
  24380.        ;
  24381.  
  24382.  param_list_opt:
  24383.          /* empty */
  24384.        | param_list
  24385.        ;
  24386.  
  24387.  param_list:
  24388.          NAME
  24389.        | param_list ',' NAME
  24390.        ;
  24391.  
  24392.  pattern:
  24393.          Begin
  24394.        | End
  24395.        | expr
  24396.        | expr ',' newline_opt expr
  24397.        ;
  24398.  
  24399.  action:
  24400.          '{' newline_opt '}'
  24401.        | '{' newline_opt terminated_statement_list '}'
  24402.        | '{' newline_opt unterminated_statement_list '}'
  24403.        ;
  24404.  
  24405.  terminator:
  24406.          ';'
  24407.        | NEWLINE
  24408.        | terminator NEWLINE ';'                                             2
  24409.  
  24410.  
  24411.                Copyright c 1991 IEEE.  All rights reserved.
  24412.       This is an unapproved IEEE Standards Draft, subject to change.
  24413.  
  24414.  
  24415.  
  24416.  
  24417.  
  24418.  340                                     4 Execution Environment Utilities
  24419.  
  24420.  
  24421.  
  24422.  
  24423.  
  24424.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24425.  
  24426.        ;
  24427.  
  24428.  terminated_statement_list:
  24429.          terminated_statement
  24430.        | terminated_statement_list terminated_statement
  24431.        ;
  24432.  
  24433.  unterminated_statement_list:
  24434.          unterminated_statement
  24435.        | terminated_statement_list unterminated_statement
  24436.        ;
  24437.  
  24438.  terminated_statement:
  24439.          action newline_opt
  24440.        | If '(' expr ')' newline_opt terminated_statement
  24441.          Else newline_opt terminated_statement
  24442.        | While '(' expr ')' newline_opt terminated_statement
  24443.        | For '(' simple_statement_opt ';' expr_opt ';' simple_statement_opt ')'
  24444.          newline_opt terminated_statement
  24445.        | For '(' NAME In NAME ')' newline_opt terminated_statement
  24446.        | ';' newline_opt
  24447.        | terminatable_statement NEWLINE newline_opt
  24448.        | terminatable_statement ';' newline_opt
  24449.        ;
  24450.  
  24451.  unterminated_statement:
  24452.          terminatable_statement
  24453.        | If '(' expr ')' newline_opt unterminated_statement
  24454.        | If '(' expr ')' newline_opt terminated_statement
  24455.          Else newline_opt unterminated_statement
  24456.        | While '(' expr ')' newline_opt unterminated_statement
  24457.        | For '(' simple_statement_opt ';' expr_opt ';' simple_statement_opt ')'
  24458.          newline_opt unterminated_statement
  24459.        | For '(' NAME In NAME ')' newline_opt unterminated_statement
  24460.        ;
  24461.  
  24462.  terminatable_statement:
  24463.          simple_statement
  24464.        | Break
  24465.        | Continue
  24466.        | Next
  24467.        | Exit expr_opt
  24468.        | Return expr_opt
  24469.        | Do newline_opt terminated_statement While '(' expr ')'
  24470.        ;
  24471.  
  24472.  simple_statement_opt:
  24473.          /* empty */
  24474.        | simple_statement
  24475.  
  24476.  
  24477.                Copyright c 1991 IEEE.  All rights reserved.
  24478.       This is an unapproved IEEE Standards Draft, subject to change.
  24479.  
  24480.  
  24481.  
  24482.  
  24483.  
  24484.  4.1 awk - Pattern scanning and processing language                    341
  24485.  
  24486.  
  24487.  
  24488.  
  24489.  
  24490.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24491.  
  24492.        ;
  24493.  
  24494.  simple_statement:
  24495.          Delete NAME '[' expr_list ']'
  24496.        | expr
  24497.        | print_statement
  24498.        ;
  24499.  
  24500.  print_statement:
  24501.          simple_print_statement
  24502.        | simple_print_statement output_redirection
  24503.        ;
  24504.  
  24505.  simple_print_statement:
  24506.          Print print_expr_list_opt
  24507.        | Print '(' multiple_expr_list ')'
  24508.        | Printf print_expr_list
  24509.        | Printf '(' multiple_expr_list ')'
  24510.        ;
  24511.  
  24512.  output_redirection:
  24513.          '>' expr
  24514.        | APPEND expr
  24515.        | '|' expr
  24516.        ;
  24517.  
  24518.  expr_list_opt:
  24519.          /* empty */
  24520.        | expr_list
  24521.        ;
  24522.  
  24523.  expr_list:
  24524.          expr
  24525.        | multiple_expr_list
  24526.        ;
  24527.  
  24528.  multiple_expr_list:
  24529.          expr ',' newline_opt expr
  24530.        | multiple_expr_list ',' newline_opt expr
  24531.        ;
  24532.  
  24533.  expr_opt:
  24534.          /* empty */
  24535.        | expr
  24536.        ;
  24537.  
  24538.  expr:
  24539.          unary_expr
  24540.        | non_unary_expr
  24541.  
  24542.  
  24543.                Copyright c 1991 IEEE.  All rights reserved.
  24544.       This is an unapproved IEEE Standards Draft, subject to change.
  24545.  
  24546.  
  24547.  
  24548.  
  24549.  
  24550.  342                                     4 Execution Environment Utilities
  24551.  
  24552.  
  24553.  
  24554.  
  24555.  
  24556.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24557.  
  24558.        ;
  24559.  
  24560.  unary_expr:
  24561.          '+' expr
  24562.        | '-' expr
  24563.        | unary_expr '^' expr
  24564.        | unary_expr '*' expr
  24565.        | unary_expr '/' expr
  24566.        | unary_expr '%' expr
  24567.        | unary_expr '+' expr
  24568.        | unary_expr '-' expr
  24569.        | unary_expr non_unary_expr
  24570.        | unary_expr '<' expr
  24571.        | unary_expr LE expr
  24572.        | unary_expr NE expr
  24573.        | unary_expr EQ expr
  24574.        | unary_expr '>' expr
  24575.        | unary_expr GE expr
  24576.        | unary_expr ' ' expr
  24577.        | unary_expr N~O_MATCH expr
  24578.        | unary_expr In NAME
  24579.        | unary_expr AND newline_opt expr
  24580.        | unary_expr OR newline_opt expr
  24581.        | unary_expr '?' expr ':' expr
  24582.        | unary_input_function
  24583.        ;
  24584.  
  24585.  non_unary_expr:
  24586.          '(' expr ')'
  24587.        | '!' expr
  24588.        | non_unary_expr '^' expr
  24589.        | non_unary_expr '*' expr
  24590.        | non_unary_expr '/' expr
  24591.        | non_unary_expr '%' expr
  24592.        | non_unary_expr '+' expr
  24593.        | non_unary_expr '-' expr
  24594.        | non_unary_expr non_unary_expr
  24595.        | non_unary_expr '<' expr
  24596.        | non_unary_expr LE expr
  24597.        | non_unary_expr NE expr
  24598.        | non_unary_expr EQ expr
  24599.        | non_unary_expr '>' expr
  24600.        | non_unary_expr GE expr
  24601.        | non_unary_expr ' ' expr
  24602.        | non_unary_expr N~O_MATCH expr
  24603.        | non_unary_expr In NAME
  24604.        | '(' multiple_expr_list ')' In NAME
  24605.        | non_unary_expr AND newline_opt expr
  24606.        | non_unary_expr OR newline_opt expr
  24607.  
  24608.  
  24609.                Copyright c 1991 IEEE.  All rights reserved.
  24610.       This is an unapproved IEEE Standards Draft, subject to change.
  24611.  
  24612.  
  24613.  
  24614.  
  24615.  
  24616.  4.1 awk - Pattern scanning and processing language                    343
  24617.  
  24618.  
  24619.  
  24620.  
  24621.  
  24622.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24623.  
  24624.        | non_unary_expr '?' expr ':' expr
  24625.        | NUMBER
  24626.        | STRING
  24627.        | lvalue
  24628.        | ERE
  24629.        | lvalue INCR
  24630.        | lvalue DECR
  24631.        | INCR lvalue
  24632.        | DECR lvalue
  24633.        | lvalue POW_ASSIGN expr
  24634.        | lvalue MOD_ASSIGN expr
  24635.        | lvalue MUL_ASSIGN expr
  24636.        | lvalue DIV_ASSIGN expr
  24637.        | lvalue ADD_ASSIGN expr
  24638.        | lvalue SUB_ASSIGN expr
  24639.        | lvalue '=' expr
  24640.        | FUNC_NAME '(' expr_list_opt ')'  /* no white space allowed */
  24641.        | BUILTIN_FUNC_NAME '(' expr_list_opt ')'
  24642.        | BUILTIN_FUNC_NAME
  24643.        | non_unary_input_function
  24644.        ;
  24645.  
  24646.  print_expr_list_opt:
  24647.          /* empty */
  24648.        | print_expr_list
  24649.        ;
  24650.  
  24651.  print_expr_list:
  24652.          print_expr
  24653.        | print_expr_list ',' newline_opt print_expr
  24654.        ;
  24655.  
  24656.  print_expr:
  24657.          unary_print_expr
  24658.        | non_unary_print_expr
  24659.        ;
  24660.  
  24661.  unary_print_expr:
  24662.          '+' print_expr
  24663.        | '-' print_expr
  24664.        | unary_print_expr '^' print_expr
  24665.        | unary_print_expr '*' print_expr
  24666.        | unary_print_expr '/' print_expr
  24667.        | unary_print_expr '%' print_expr
  24668.        | unary_print_expr '+' print_expr
  24669.        | unary_print_expr '-' print_expr
  24670.        | unary_print_expr non_unary_print_expr
  24671.        | unary_print_expr ' ' print_expr
  24672.        | unary_print_expr N~O_MATCH print_expr
  24673.  
  24674.  
  24675.                Copyright c 1991 IEEE.  All rights reserved.
  24676.       This is an unapproved IEEE Standards Draft, subject to change.
  24677.  
  24678.  
  24679.  
  24680.  
  24681.  
  24682.  344                                     4 Execution Environment Utilities
  24683.  
  24684.  
  24685.  
  24686.  
  24687.  
  24688.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24689.  
  24690.        | unary_print_expr In NAME
  24691.        | unary_print_expr AND newline_opt print_expr
  24692.        | unary_print_expr OR newline_opt print_expr
  24693.        | unary_print_expr '?' print_expr ':' print_expr
  24694.        ;
  24695.  
  24696.  non_unary_print_expr:
  24697.          '(' expr ')'
  24698.        | '!' print_expr
  24699.        | non_unary_print_expr '^' print_expr
  24700.        | non_unary_print_expr '*' print_expr
  24701.        | non_unary_print_expr '/' print_expr
  24702.        | non_unary_print_expr '%' print_expr
  24703.        | non_unary_print_expr '+' print_expr
  24704.        | non_unary_print_expr '-' print_expr
  24705.        | non_unary_print_expr non_unary_print_expr
  24706.        | non_unary_print_expr ' ' print_expr
  24707.        | non_unary_print_expr N~O_MATCH print_expr
  24708.        | non_unary_print_expr In NAME
  24709.        | '(' multiple_expr_list ')' In NAME
  24710.        | non_unary_print_expr AND newline_opt print_expr
  24711.        | non_unary_print_expr OR newline_opt print_expr
  24712.        | non_unary_print_expr '?' print_expr ':' print_expr
  24713.        | NUMBER
  24714.        | STRING
  24715.        | lvalue
  24716.        | ERE
  24717.        | lvalue INCR
  24718.        | lvalue DECR
  24719.        | INCR lvalue
  24720.        | DECR lvalue
  24721.        | lvalue POW_ASSIGN print_expr
  24722.        | lvalue MOD_ASSIGN print_expr
  24723.        | lvalue MUL_ASSIGN print_expr
  24724.        | lvalue DIV_ASSIGN print_expr
  24725.        | lvalue ADD_ASSIGN print_expr
  24726.        | lvalue SUB_ASSIGN print_expr
  24727.        | lvalue '=' print_expr
  24728.        | FUNC_NAME '(' expr_list_opt ')' /* no white space allowed */
  24729.        | BUILTIN_FUNC_NAME '(' expr_list_opt ')'
  24730.        | BUILTIN_FUNC_NAME
  24731.        ;
  24732.  
  24733.  lvalue:
  24734.          NAME
  24735.        | NAME '[' expr_list ']'
  24736.        | '$' expr
  24737.        ;
  24738.  
  24739.  
  24740.  
  24741.                Copyright c 1991 IEEE.  All rights reserved.
  24742.       This is an unapproved IEEE Standards Draft, subject to change.
  24743.  
  24744.  
  24745.  
  24746.  
  24747.  
  24748.  4.1 awk - Pattern scanning and processing language                    345
  24749.  
  24750.  
  24751.  
  24752.  
  24753.  
  24754.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24755.  
  24756.  non_unary_input_function:
  24757.          simple_get
  24758.        | simple_get '<' expr
  24759.        | non_unary_expr '|' simple_get
  24760.        ;
  24761.  
  24762.  unary_input_function:
  24763.          unary_expr '|' simple_get
  24764.        ;
  24765.  
  24766.  simple_get:
  24767.          GETLINE
  24768.        | GETLINE lvalue
  24769.        ;
  24770.  
  24771.  newline_opt:
  24772.          /* empty */
  24773.        | newline_opt NEWLINE
  24774.        ;
  24775.  
  24776.  This grammar has several ambiguities that shall be resolved as follows:
  24777.  
  24778.      - Operator precedence and associativity shall be as described in
  24779.        Table 4-1.
  24780.  
  24781.      - In case of ambiguity, an else shall be associated with the most
  24782.        immediately preceding if that would satisfy the grammar.
  24783.  
  24784.  
  24785.  4.1.7.8  awk Lexical Conventions
  24786.  
  24787.  The lexical conventions for awk programs, with respect to the preceding
  24788.  grammar, shall be as follows:
  24789.  
  24790.      (1)  Except as noted, awk shall recognize the longest possible token
  24791.           or delimiter beginning at a given point.
  24792.  
  24793.      (2)  A comment shall consist of any characters beginning with the
  24794.           number sign character and terminated by, but excluding the next
  24795.           occurrence of, a <newline> character.  Comments shall have no
  24796.           effect, except to delimit lexical tokens.
  24797.  
  24798.      (3)  The character <newline> shall be recognized as the token
  24799.           NEWLINE.
  24800.  
  24801.      (4)  A backslash character immediately followed by a <newline>         1
  24802.           character shall have no effect.                                   1
  24803.  
  24804.  
  24805.  
  24806.  
  24807.                Copyright c 1991 IEEE.  All rights reserved.
  24808.       This is an unapproved IEEE Standards Draft, subject to change.
  24809.  
  24810.  
  24811.  
  24812.  
  24813.  
  24814.  346                                     4 Execution Environment Utilities
  24815.  
  24816.  
  24817.  
  24818.  
  24819.  
  24820.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24821.  
  24822.      (5)  The token STRING shall represent a string constant.  A string
  24823.           constant shall begin with the character ".  Within a string
  24824.           constant, a backslash character shall be considered to begin an
  24825.           escape sequence as specified in Table 2-15 (see 2.12).  In
  24826.           addition, the escape sequences in Table 4-2 shall be recognized.
  24827.           A <newline> character shall not occur within a string constant.
  24828.           A string constant shall be terminated by the first unescaped
  24829.           occurrence of the character " after the one that begins the
  24830.           string constant.  The value of the string shall be the sequence
  24831.           of all unescaped characters and values of escape sequences
  24832.           between, but not including, the two delimiting " characters.
  24833.  
  24834.  
  24835.                     Table 4-2  -  awk Escape Sequences
  24836.  __________________________________________________________________________________________________________________________________________________
  24837.         Escape
  24838.        Sequence        Description                  Meaning
  24839.        _____________________________________________________________
  24840.  
  24841.           \"      <backslash>              <quotation-mark>
  24842.                   <quotation-mark>         character
  24843.  
  24844.           \/      <backslash> <slash>      <slash> character
  24845.  
  24846.          \_d_d_d     <backslash> followed     The character whose              111
  24847.                   by the longest           encoding is represented          11
  24848.                   sequence of one, two,    by the one-, two-, or            11
  24849.                   or three octal-digit     three-digit octal                11
  24850.                   characters (01234567).   integer.  If the size of         11
  24851.                   If all of the digits     a byte on the system is          11
  24852.                   are 0, (i.e.,            greater than nine bits,          11
  24853.                   representation of the    the valid escape sequence        11
  24854.                   NUL character), the      used to represent a byte         11
  24855.                   behavior is undefined.   is implementation                11
  24856.                                            defined.  Multibyte              1
  24857.                                            characters require               1
  24858.                                            multiple, concatenated           1
  24859.                                            escape sequences of this         1
  24860.                                            type, including the              1
  24861.                                            leading \ for each byte.         1
  24862.  
  24863.           \_c      <backslash> followed     Undefined
  24864.                   by any character not
  24865.                   described in this
  24866.                   table or in Table 2-15
  24867.  __________________________________________________________________________________________________________________________________________________
  24868.  
  24869.  
  24870.  
  24871.  
  24872.  
  24873.                Copyright c 1991 IEEE.  All rights reserved.
  24874.       This is an unapproved IEEE Standards Draft, subject to change.
  24875.  
  24876.  
  24877.  
  24878.  
  24879.  
  24880.  4.1 awk - Pattern scanning and processing language                    347
  24881.  
  24882.  
  24883.  
  24884.  
  24885.  
  24886.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  24887.  
  24888.      (6)  The token ERE represents an extended regular expression
  24889.           constant.  An ERE constant shall begin with the slash character.
  24890.           Within an ERE constant, a <backslash> character shall be
  24891.           considered to begin an escape sequence as specified in Table 2-
  24892.           15 (see 2.12).  In addition, the escape sequences in Table 4-2    1
  24893.           shall be recognized.  A <newline> character shall not occur
  24894.           within an ERE constant.  An ERE constant shall be terminated by
  24895.           the first unescaped occurrence of the slash character after the
  24896.           one that begins the string constant.  The extended regular
  24897.           expression represented by the ERE constant shall be the sequence
  24898.           of all unescaped characters and values of escape sequences
  24899.           between, but not including, the two delimiting slash characters.
  24900.  
  24901.      (7)  A <blank> shall have no effect, except to delimit lexical tokens
  24902.           or within STRING or ERE tokens.
  24903.  
  24904.      (8)  The token NUMBER shall represent a numeric constant.  Its form
  24905.           and numeric value shall be equivalent to the either of the
  24906.           tokens floating-constant or integer-constant as specified by the
  24907.           C Standard {7}, with the following exceptions:
  24908.  
  24909.            (a)  An integer constant cannot begin with 0x or include the
  24910.                 hexadecimal digits a, b, c, d, e, f, A, B, C, D, E, or F.
  24911.  
  24912.            (b)  The value of an integer constant beginning with 0 shall be
  24913.                 taken in decimal rather than octal.
  24914.  
  24915.            (c)  An integer constant cannot include a suffix (u, U, l, or
  24916.                 L).
  24917.  
  24918.            (d)  A floating constant cannot include a suffix (f, F, l, or
  24919.                 L).
  24920.  
  24921.           If the value is too large or too small to be representable (see
  24922.           2.9.2.1), the behavior is undefined.
  24923.  
  24924.      (9)  A sequence of underscores, digits, and alphabetics from the
  24925.           portable character set (see 2.4), beginning with an underscore
  24926.           or alphabetic, shall be considered a word.
  24927.  
  24928.     (10)  The following words are keywords that shall be recognized as
  24929.           individual tokens; the name of the token is the same as the
  24930.           keyword:
  24931.  
  24932.                    BEGIN      delete   for        in      printf
  24933.                    END        do       function   next    return
  24934.                    break      else     getline    print   while
  24935.  
  24936.  
  24937.  
  24938.  
  24939.                Copyright c 1991 IEEE.  All rights reserved.
  24940.       This is an unapproved IEEE Standards Draft, subject to change.
  24941.  
  24942.  
  24943.  
  24944.  
  24945.  
  24946.  348                                     4 Execution Environment Utilities
  24947.  
  24948.  
  24949.  
  24950.  
  24951.  
  24952.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  24953.  
  24954.                    continue   exit     if
  24955.  
  24956.     (11)  The following words are names of built-in functions and shall be
  24957.           recognized as the token BUILTIN_FUNC_NAME:
  24958.  
  24959.                      atan2   index    match   sprintf   substr
  24960.                      close   int      rand    sqrt      system
  24961.                      cos     length   sin     srand     tolower
  24962.                      exp     log      split   sub       toupper
  24963.                      gsub
  24964.  
  24965.           The above-listed keywords and names of built-in functions are
  24966.           considered reserved words.
  24967.  
  24968.     (12)  The token NAME shall consist of a word that is not a keyword or
  24969.           a name of a built-in function and is not followed immediately
  24970.           (without any delimiters) by the ( character.
  24971.  
  24972.     (13)  The token FUNC_NAME shall consist of a word that is not a
  24973.           keyword or a name of a built-in function, followed immediately
  24974.           (without any delimiters) by the ( character.  The ( character
  24975.           shall not be included as part of the token.
  24976.  
  24977.     (14)  The following two-character sequences shall be recognized as the
  24978.           named tokens:
  24979.  
  24980.                   Token Name   Sequence     Token Name   Sequence
  24981.                   __________   ________     __________   ________
  24982.                   ADD_ASSIGN      +=        NO_MATCH        !~
  24983.                   SUB_ASSIGN      -=        EQ              ==
  24984.                   MUL_ASSIGN      *=        LE              <=
  24985.                   DIV_ASSIGN      /=        GE              >=
  24986.                   MOD_ASSIGN      %=        NE              !=
  24987.                   POW_ASSIGN      ^=        INCR            ++
  24988.                   OR              ||        DECR            --
  24989.                   AND             &&        APPEND          >>
  24990.  
  24991.     (15)  The following single characters shall be recognized as tokens
  24992.           whose names are the character:
  24993.  
  24994.                 <newline>  {  }  (  )  [  ]  ,  ;  +  -  *  %  ^  !  >  <  |  ?  :  ~  $  =
  24995.  
  24996.  There is a lexical ambiguity between the token ERE and the tokens / and
  24997.  DIV_ASSIGN.  When an input sequence begins with a slash character in any
  24998.  syntactic context where the token / or DIV_ASSIGN could appear as the
  24999.  next token in a valid program, the longer of those two tokens that can be
  25000.  recognized shall be recognized.  In any other syntactic context where the
  25001.  token ERE could appear as the next token in a valid program, the token
  25002.  ERE shall be recognized.
  25003.  
  25004.  
  25005.                Copyright c 1991 IEEE.  All rights reserved.
  25006.       This is an unapproved IEEE Standards Draft, subject to change.
  25007.  
  25008.  
  25009.  
  25010.  
  25011.  
  25012.  4.1 awk - Pattern scanning and processing language                    349
  25013.  
  25014.  
  25015.  
  25016.  
  25017.  
  25018.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25019.  
  25020.  4.1.8  Exit Status
  25021.  
  25022.  The awk utility shall exit with one of the following values:
  25023.  
  25024.      0    All input files were processed successfully.
  25025.  
  25026.     >0    An error occurred.
  25027.  
  25028.  The exit status can be altered within the program by using an exit
  25029.  expression.
  25030.  
  25031.  
  25032.  4.1.9  Consequences of Errors
  25033.  
  25034.  If any _f_i_l_e operand is specified and the named file cannot be accessed,
  25035.  awk shall write a diagnostic message to standard error and terminate
  25036.  without any further action.
  25037.  
  25038.  If the program specified by either the _p_r_o_g_r_a_m operand or the _p_r_o_g_f_i_l_e
  25039.  operand(s) is not a valid awk program (as specified in 4.1.7), the
  25040.  behavior is undefined.
  25041.  
  25042.  BEGIN_RATIONALE
  25043.  
  25044.  
  25045.  4.1.10  Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  25046.  
  25047.  _E_x_a_m_p_l_e_s_,__U_s_a_g_e
  25048.  
  25049.  The awk program specified in the command line is most easily specified
  25050.  within single-quotes (e.g., '_p_r_o_g_r_a_m') for applications using sh, because
  25051.  awk programs commonly contain characters that are special to the shell,
  25052.  including double-quotes.  In the cases where an awk program contains
  25053.  single-quote characters, it is usually easiest to specify most of the
  25054.  program as strings within single-quotes concatenated by the shell with
  25055.  quoted single-quote characters.  For example,
  25056.  
  25057.        awk '/'\''/ { print "quote:", $0 }'
  25058.  
  25059.  prints all lines from the standard input containing a single-quote
  25060.  character, prefixed with quote:.
  25061.  
  25062.  The following are examples of simple awk programs:
  25063.  
  25064.      (1)  Write to the standard output all input lines for which field 3
  25065.           is greater than 5.
  25066.  
  25067.                 $3 > 5
  25068.  
  25069.  
  25070.  
  25071.                Copyright c 1991 IEEE.  All rights reserved.
  25072.       This is an unapproved IEEE Standards Draft, subject to change.
  25073.  
  25074.  
  25075.  
  25076.  
  25077.  
  25078.  350                                     4 Execution Environment Utilities
  25079.  
  25080.  
  25081.  
  25082.  
  25083.  
  25084.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25085.  
  25086.      (2)  Write every tenth line.
  25087.  
  25088.                 (NR % 10) == 0
  25089.  
  25090.      (3)  Write any line with a substring matching the regular expression.
  25091.  
  25092.                 /(G|D)(2[0-9][[:alpha:]]*)/
  25093.  
  25094.      (4)  Write any line in which the second field matches the regular
  25095.           expression and the fourth field does not.
  25096.  
  25097.                 $2   /xyz/ && $4 !  /xyz/
  25098.                    ~              ~
  25099.      (5)  Write any line in which the second field contains a backslash.
  25100.  
  25101.                 $2   /\\/
  25102.                    ~
  25103.      (6)  Write any line in which the second field contains a backslash.
  25104.           Note that backslash escapes are interpreted twice, once in
  25105.           lexical processing of the string and once in processing the
  25106.           regular expression.
  25107.  
  25108.                 $2   "\\\\"
  25109.                    ~
  25110.      (7)  Write the second to the last and the last field in each line.
  25111.           Separate the fields by a colon.
  25112.  
  25113.                 {OFS=":";print $(NF-1), $NF}
  25114.  
  25115.      (8)  Write the line number and number of fields in each line.  The
  25116.           three strings representing the line number, the colon and the
  25117.           number of fields are concatenated and that string is written to
  25118.           standard output.
  25119.  
  25120.                 {print NR ":" NF}
  25121.  
  25122.      (9)  Write lines longer than 72 characters.
  25123.  
  25124.                 {length($0) > 72}
  25125.  
  25126.     (10)  Write first two fields in opposite order separated by the OFS:
  25127.  
  25128.                 { print $2, $1 }
  25129.  
  25130.     (11)  Same, with input fields separated by comma and/or <space>_s and
  25131.           <tab>_s:
  25132.  
  25133.  
  25134.  
  25135.  
  25136.  
  25137.                Copyright c 1991 IEEE.  All rights reserved.
  25138.       This is an unapproved IEEE Standards Draft, subject to change.
  25139.  
  25140.  
  25141.  
  25142.  
  25143.  
  25144.  4.1 awk - Pattern scanning and processing language                    351
  25145.  
  25146.  
  25147.  
  25148.  
  25149.  
  25150.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25151.  
  25152.                 BEGIN   { FS = ",[ \t]*|[ \t]+" }
  25153.                         { print $2, $1 }
  25154.  
  25155.     (12)  Add up first column, print sum and average.
  25156.  
  25157.                         {s += $1 }
  25158.                 END     {print "sum is ", s, " average is", s/NR}
  25159.  
  25160.     (13)  Write fields in reverse order, one per line (many lines out for
  25161.           each line in):
  25162.  
  25163.                 { for (i = NF; i > 0; --i) print $i }
  25164.  
  25165.     (14)  Write all lines between occurrences of the strings start and
  25166.           stop:
  25167.  
  25168.                 /start/, /stop/
  25169.  
  25170.     (15)  Write all lines whose first field is different from the previous
  25171.           one:
  25172.  
  25173.                 $1 != prev { print; prev = $1 }
  25174.  
  25175.     (16)  Simulate echo:
  25176.  
  25177.                 BEGIN   {
  25178.                         for (i = 1; i < ARGC; ++i)
  25179.                                 printf "%s%s", ARGV[i], i==ARGC-1?"\n":""
  25180.                 }
  25181.  
  25182.     (17)  Write the path prefixes contained in the PATH environment
  25183.           variable, one per line:
  25184.  
  25185.                 BEGIN   {
  25186.                         n = split (ENVIRON["PATH"], path, ":")
  25187.                         for (i = 1; i <= n; ++i)
  25188.                                 print path[i]
  25189.                 }
  25190.  
  25191.     (18)  If there is a file named ``input'' containing page headers of
  25192.           the form:
  25193.  
  25194.                                 Page #
  25195.  
  25196.           and a file named ``program'' that contains:
  25197.  
  25198.                         /Page/{ $2 = n++; }
  25199.                         { print }
  25200.  
  25201.  
  25202.  
  25203.                Copyright c 1991 IEEE.  All rights reserved.
  25204.       This is an unapproved IEEE Standards Draft, subject to change.
  25205.  
  25206.  
  25207.  
  25208.  
  25209.  
  25210.  352                                     4 Execution Environment Utilities
  25211.  
  25212.  
  25213.  
  25214.  
  25215.  
  25216.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25217.  
  25218.           then the command line:
  25219.  
  25220.                 awk -f program n=5 input
  25221.  
  25222.           will print the file ``input,'' filling in page numbers starting
  25223.           at 5.
  25224.  
  25225.  The index, length, match, and substr should not be confused with similar
  25226.  functions in the C Standard {7}; the awk versions deal with characters,
  25227.  while the C Standard {7} deals with bytes.
  25228.  
  25229.  To forestall any possible confusion, where strings are used as the name    1
  25230.  of a file or pipeline, the strings must be textually identical.  The       1
  25231.  terminology ``same string value'' implies that ``equivalent strings,''     1
  25232.  even those that differ only by <space>s, represent different files.        1
  25233.  
  25234.  _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e
  25235.  
  25236.  This description is based on the new awk, ``nawk,'' (see _T_h_e _A_W_K
  25237.  _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e {B21}), which introduced a number of new features to
  25238.  the historical awk:
  25239.  
  25240.      (1)  New keywords:  delete, do, function, return
  25241.  
  25242.      (2)  New built-in functions:  atan2, cos, sin, rand, srand, gsub,
  25243.           sub, match, close, system
  25244.  
  25245.      (3)  New predefined variables:  FNR, ARGC, ARGV, RSTART, RLENGTH,
  25246.           SUBSEP
  25247.  
  25248.      (4)  New expression operators:  ?:, ^
  25249.  
  25250.      (5)  The FS variable and the third argument to split are now treated
  25251.           as extended regular expressions.
  25252.  
  25253.      (6)  The operator precedence has changed to more closely match C.
  25254.           Two examples of code that operate differently are:
  25255.  
  25256.                 while ( n /= 10 > 1) ...
  25257.                 if (!"wk"   /bwk/) ...
  25258.                           ~
  25259.  Several features have been added based on newer implementations of awk:
  25260.  
  25261.      (1)  Multiple instances of -f _p_r_o_g_f_i_l_e are permitted.
  25262.  
  25263.      (2)  New option:  -v _a_s_s_i_g_n_m_e_n_t
  25264.  
  25265.      (3)  New predefined variable:  ENVIRON
  25266.  
  25267.  
  25268.  
  25269.                Copyright c 1991 IEEE.  All rights reserved.
  25270.       This is an unapproved IEEE Standards Draft, subject to change.
  25271.  
  25272.  
  25273.  
  25274.  
  25275.  
  25276.  4.1 awk - Pattern scanning and processing language                    353
  25277.  
  25278.  
  25279.  
  25280.  
  25281.  
  25282.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25283.  
  25284.      (4)  New built-in functions:  toupper, tolower
  25285.  
  25286.      (5)  More formatting capabilities added to printf to match the
  25287.           C Standard {7}.
  25288.  
  25289.  Regular expressions have been extended somewhat from traditional
  25290.  implementations to make them a pure superset of Extended Regular
  25291.  Expressions as defined by this standard (see 2.8.4).  The main extensions
  25292.  are internationalization features and interval expressions.  Traditional
  25293.  implementations of awk have long supported <backslash> escape sequences
  25294.  as an extension to regular expressions, and this extension has been
  25295.  retained despite inconsistency with other utilities.  The number of
  25296.  escape sequences recognized in both regular expressions and strings has
  25297.  varied (generally increasing with time) among implementations.  The set
  25298.  specified by the standard includes most sequences known to be supported
  25299.  by popular implementations and by the C Standard {7}.  One sequence that
  25300.  is not supported is hexadecimal value escapes beginning with "\x".  This
  25301.  would allow values expressed in more than 9 bits to be used within awk as
  25302.  in the C Standard {7}.  However, because this syntax has a
  25303.  nondeterministic length, it does not permit the subsequent character to
  25304.  be a hexadecimal digit.  This limitation can be worked around in the
  25305.  C language by the use of lexical string concatenation.  In the awk
  25306.  language, concatenation could also be a solution for strings, but not for
  25307.  regular expressions (either lexical ERE tokens or strings used
  25308.  dynamically as regular expressions).  Because of this limitation, the
  25309.  feature has not been added to POSIX.2.
  25310.  
  25311.  When a string variable is used in a context where an ERE normally appears  1
  25312.  (where the lexical token ERE is used in the grammar) the string does not   1
  25313.  contain the literal slashes.                                               1
  25314.  
  25315.  Some versions of awk allow the form:
  25316.  
  25317.        func _n_a_m_e(_a_r_g_s,...) {  _s_t_a_t_e_m_e_n_t_s }
  25318.  
  25319.  This has been deprecated by the language's authors, who have asked that
  25320.  it not be included in the standard.
  25321.  
  25322.  Traditional implementations of awk produce an error if a next statement
  25323.  is executed in a BEGIN action, and cause awk to terminate if a next
  25324.  statement is executed in an END action.  This behavior has not been
  25325.  documented, and it was not believed that it was necessary to standardize
  25326.  it.
  25327.  
  25328.  The specification of conversions between string and numeric values is
  25329.  much more detailed than in the documentation of traditional
  25330.  implementations or in _T_h_e _A_W_K _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e {B21}.  Although most
  25331.  of the behavior is designed to be intuitive, the details are necessary to
  25332.  ensure compatible behavior from different implementations.  This is
  25333.  
  25334.  
  25335.                Copyright c 1991 IEEE.  All rights reserved.
  25336.       This is an unapproved IEEE Standards Draft, subject to change.
  25337.  
  25338.  
  25339.  
  25340.  
  25341.  
  25342.  354                                     4 Execution Environment Utilities
  25343.  
  25344.  
  25345.  
  25346.  
  25347.  
  25348.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25349.  
  25350.  especially important in relational expressions, since the types of the
  25351.  operands determine whether a string or numeric comparison is performed.
  25352.  From the perspective of an application writer, it is usually sufficient
  25353.  to expect intuitive behavior and to force conversions (by adding zero or
  25354.  concatenating a null string) when the type of an expression does not
  25355.  obviously match what is needed.  The intent has been to specify existing
  25356.  practice in almost all cases.  The one exception is that, in traditional
  25357.  implementations, variables and constants maintain both string and numeric
  25358.  values after their original value is converted by any use.  This means
  25359.  that referencing a variable or constant can have unexpected side effects.
  25360.  For example, with traditional implementations the following program:
  25361.  
  25362.        {
  25363.                a = "+2"
  25364.                b = 2
  25365.                if (NR % 2)
  25366.                        c = a + b
  25367.                if (a == b)
  25368.                        print "numeric comparison"
  25369.                else
  25370.                        print "string comparison"
  25371.        }
  25372.  
  25373.  would perform a numeric comparison (and output numeric comparison) for
  25374.  each odd-numbered line, but perform a string comparison (and output
  25375.  string comparison) for each even-numbered line.  POSIX.2 ensures that      1
  25376.  comparisons will be numeric if necessary.  With traditional                1
  25377.  implementations, the following program:
  25378.  
  25379.        BEGIN {
  25380.                OFMT = "%e"
  25381.                print 3.14
  25382.                OFMT = "%f"
  25383.                print 3.14
  25384.        }
  25385.  
  25386.  would output 3.140000e+00 twice, because in the second print statement
  25387.  the constant 3.14 would have a string value from the previous conversion.
  25388.  The standard requires that the output of the second print statement be
  25389.  3.140000.  The behavior of traditional implementations was seen as too
  25390.  unintuitive and unpredictable.
  25391.  
  25392.  However, a further modification was made in Draft 11.  It was pointed out
  25393.  that with the Draft 10 rules, the following script would print nothing:
  25394.  
  25395.  
  25396.  
  25397.  
  25398.  
  25399.  
  25400.  
  25401.                Copyright c 1991 IEEE.  All rights reserved.
  25402.       This is an unapproved IEEE Standards Draft, subject to change.
  25403.  
  25404.  
  25405.  
  25406.  
  25407.  
  25408.  4.1 awk - Pattern scanning and processing language                    355
  25409.  
  25410.  
  25411.  
  25412.  
  25413.  
  25414.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25415.  
  25416.        BEGIN {
  25417.                y[1.5] = 1
  25418.                OFMT = "%e"
  25419.                print y[1.5]
  25420.        }
  25421.  
  25422.  Therefore, a new variable, CONVFMT, was introduced.  The OFMT variable is
  25423.  now restricted to affecting output conversions of numbers to strings and
  25424.  CONVFMT is used for internal conversions, such as comparisons or array
  25425.  indexing.  The default value is the same as that for OFMT, so unless a
  25426.  program changes CONVFMT (which no historical program would do), it will
  25427.  receive the historical behavior associated with internal string
  25428.  conversions.
  25429.  
  25430.  The POSIX awk lexical and syntactic conventions are specified more
  25431.  formally than in other sources.  Again the intent has been to specify
  25432.  existing practice.  One convention that may not be obvious from the
  25433.  formal grammar as in other verbal descriptions is where <newline>_s are
  25434.  acceptable.  There are several obvious placements such as terminating a
  25435.  statement, and a backslash can be used to escape <newline>_s between any
  25436.  lexical tokens.  In addition, <newline>_s without backslashes can follow a
  25437.  comma, an open brace, logical AND operator (&&), _l_o_g_i_c_a_l _O_R _o_p_e_r_a_t_o_r
  25438.  (||), the do keyword, the else keyword, and the closing parenthesis of an
  25439.  if, for, or while statement.  For example:
  25440.  
  25441.        { print   $1,
  25442.                  $2 }
  25443.  
  25444.  The requirement that awk add a trailing <newline> to the _p_r_o_g_r_a_m argument
  25445.  text is to simplify the grammar, making it match a text file in form.
  25446.  There is no way for an application or test suite to determine whether a
  25447.  literal <newline> is added or whether awk simply acts as if it did.
  25448.  
  25449.  Because the concatenation operation is represented by adjacent
  25450.  expressions rather than an explicit operator, it is often necessary to
  25451.  use parentheses to enforce the proper evaluation precedence.
  25452.  
  25453.  The overall awk syntax has always been based on the C language, with a
  25454.  few features from the shell command language and other sources.  Because
  25455.  of this, it is not completely compatible with any other language, which
  25456.  has caused confusion for some users.  It is not the intent of this
  25457.  standard to address such issues.  The standard has made a few relatively
  25458.  minor changes toward making the language more compatible with the
  25459.  C language as specified by the C Standard {7}; most of these changes are
  25460.  based on similar changes in recent implementations, as described above.
  25461.  There remain several C language conventions that are not in _a_w_k.  One of
  25462.  the notable ones is the comma operator, which is commonly used to specify
  25463.  multiple expressions in the C language for statement.  Also, there are
  25464.  various places where awk is more restrictive than the C language
  25465.  
  25466.  
  25467.                Copyright c 1991 IEEE.  All rights reserved.
  25468.       This is an unapproved IEEE Standards Draft, subject to change.
  25469.  
  25470.  
  25471.  
  25472.  
  25473.  
  25474.  356                                     4 Execution Environment Utilities
  25475.  
  25476.  
  25477.  
  25478.  
  25479.  
  25480.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25481.  
  25482.  regarding the type of expression that can be used in a given context.
  25483.  These limitations are due to the different features that the awk language
  25484.  does provide.
  25485.  
  25486.  This standard requires several changes from traditional implementations
  25487.  in order to support internationalization.  Probably the most subtle of
  25488.  these is the use of the decimal-point character, defined by the
  25489.  LC_NUMERIC category of the locale, in representations of floating point
  25490.  numbers.  This locale-specific character is used in recognizing numeric
  25491.  input, in converting between strings and numeric values, and in
  25492.  formatting output.  However, regardless of locale, the period character
  25493.  (the decimal-point character of the POSIX Locale) is the decimal-point
  25494.  character recognized in processing awk programs (including assignments in
  25495.  command-line arguments).  This is essentially the same convention as the
  25496.  one used in the C Standard {7}.  The difference is that the C language
  25497.  includes the _s_e_t_l_o_c_a_l_e() function, which permits an application to modify
  25498.  its locale.  Because of this capability, a C application begins executing
  25499.  with its locale set to the C locale, and only executes in the
  25500.  environment-specified locale after an explicit call to _s_e_t_l_o_c_a_l_e().
  25501.  However, adding such an elaborate new feature to the awk language was
  25502.  seen as inappropriate for POSIX.2.  It is possible to explicitly execute
  25503.  an awk program in any desired locale by setting the environment in the
  25504.  shell.
  25505.  
  25506.  The behavior in the case of invalid awk programs (including lexical,
  25507.  syntactic, and semantic errors) is undefined because it was considered
  25508.  overly limiting on implementations to specify.  In most cases such errors
  25509.  can be expected to produce a diagnostic and a nonzero exit status.
  25510.  However, some implementations may choose to extend the language in ways
  25511.  that make use of certain invalid constructs.  Other invalid constructs
  25512.  might be deemed worthy of a warning but otherwise cause some reasonable
  25513.  behavior.  Still other constructs may be very difficult to detect in some
  25514.  implementations.  Also, different implementations might detect a given
  25515.  error during an initial parsing of the program (before reading any input
  25516.  files) while others might detect it when executing the program after
  25517.  reading some input.  Implementors should be aware that diagnosing errors
  25518.  as early as possible and producing useful diagnostics can ease debugging
  25519.  of applications, and thus make an implementation more usable.
  25520.  
  25521.  The unspecified behavior from using multicharacter RS values is to allow
  25522.  possible future extensions based on regular expressions used for record
  25523.  separators.  Historical implementations take the first character of the
  25524.  string and ignore the others.
  25525.  
  25526.  The undefined behavior resulting from NULs in regular expressions allows
  25527.  future extensions for the GNU gawk program to process binary data.
  25528.  
  25529.  Unspecified behavior when split(string,array,<null>) is used is to allow
  25530.  a proposed future extension that would split up a string into an array of
  25531.  
  25532.  
  25533.                Copyright c 1991 IEEE.  All rights reserved.
  25534.       This is an unapproved IEEE Standards Draft, subject to change.
  25535.  
  25536.  
  25537.  
  25538.  
  25539.  
  25540.  4.1 awk - Pattern scanning and processing language                    357
  25541.  
  25542.  
  25543.  
  25544.  
  25545.  
  25546.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25547.  
  25548.  individual characters.
  25549.  
  25550.  END_RATIONALE
  25551.  
  25552.  
  25553.  
  25554.  4.2  basename - Return nondirectory portion of pathname
  25555.  
  25556.  
  25557.  4.2.1  Synopsis
  25558.  
  25559.  basename  _s_t_r_i_n_g [_s_u_f_f_i_x]
  25560.  
  25561.  
  25562.  4.2.2  Description
  25563.  
  25564.  The _s_t_r_i_n_g operand shall be treated as a pathname, as defined in
  25565.  2.2.2.102.  The string _s_t_r_i_n_g shall be converted to the filename
  25566.  corresponding to the last pathname component in _s_t_r_i_n_g and then the
  25567.  suffix string _s_u_f_f_i_x, if present, shall be removed.  This shall be done
  25568.  by performing actions equivalent to the following steps in order:
  25569.  
  25570.      (1)  If _s_t_r_i_n_g is //, it is implementation defined whether steps (2)
  25571.           through (5) are skipped or processed.
  25572.  
  25573.      (2)  If _s_t_r_i_n_g consists entirely of slash characters, _s_t_r_i_n_g shall be
  25574.           set to a single slash character.  In this case, skip steps (3)
  25575.           through (5).
  25576.  
  25577.      (3)  If there are any trailing slash characters in _s_t_r_i_n_g, they shall
  25578.           be removed.
  25579.  
  25580.      (4)  If there are any slash characters remaining in _s_t_r_i_n_g, the
  25581.           prefix of _s_t_r_i_n_g up to and including the last slash character in
  25582.           _s_t_r_i_n_g shall be removed.
  25583.  
  25584.      (5)  If the _s_u_f_f_i_x operand is present, is not identical to the
  25585.           characters remaining in _s_t_r_i_n_g, and is identical to a suffix of
  25586.           the characters remaining in _s_t_r_i_n_g, the suffix _s_u_f_f_i_x shall be
  25587.           removed from _s_t_r_i_n_g. Otherwise, _s_t_r_i_n_g shall not be modified by
  25588.           this step.  It shall not be considered an error if _s_u_f_f_i_x is not
  25589.           found in _s_t_r_i_n_g.
  25590.  
  25591.  The resulting string shall be written to standard output.
  25592.  
  25593.  
  25594.  
  25595.  
  25596.  
  25597.  
  25598.  
  25599.                Copyright c 1991 IEEE.  All rights reserved.
  25600.       This is an unapproved IEEE Standards Draft, subject to change.
  25601.  
  25602.  
  25603.  
  25604.  
  25605.  
  25606.  358                                     4 Execution Environment Utilities
  25607.  
  25608.  
  25609.  
  25610.  
  25611.  
  25612.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25613.  
  25614.  4.2.3  Options
  25615.  
  25616.  None.
  25617.  
  25618.  
  25619.  4.2.4  Operands
  25620.  
  25621.  The following operands shall be supported by the implementation:
  25622.  
  25623.     _s_t_r_i_n_g      A string.
  25624.  
  25625.     _s_u_f_f_i_x      A string.
  25626.  
  25627.  
  25628.  4.2.5  External Influences
  25629.  
  25630.  
  25631.  4.2.5.1  Standard Input
  25632.  
  25633.  None.
  25634.  
  25635.  4.2.5.2  Input Files
  25636.  
  25637.  None.
  25638.  
  25639.  
  25640.  4.2.5.3  Environment Variables
  25641.  
  25642.  The following environment variables shall affect the execution of
  25643.  basename:
  25644.  
  25645.     LANG               This variable shall determine the locale to use for
  25646.                        the locale categories when both LC_ALL and the
  25647.                        corresponding environment variable (beginning with
  25648.                        LC_) do not specify a locale.  See 2.6.
  25649.  
  25650.     LC_ALL             This variable shall determine the locale to be used
  25651.                        to override any values for locale categories
  25652.                        specified by the settings of LANG or any
  25653.                        environment variables beginning with LC_.
  25654.  
  25655.     LC_CTYPE           This variable shall determine the locale for the
  25656.                        interpretation of sequences of bytes of text data
  25657.                        as characters (e.g., single- versus multibyte
  25658.                        characters in arguments).
  25659.  
  25660.     LC_MESSAGES        This variable shall determine the language in which
  25661.                        messages should be written.
  25662.  
  25663.  
  25664.  
  25665.                Copyright c 1991 IEEE.  All rights reserved.
  25666.       This is an unapproved IEEE Standards Draft, subject to change.
  25667.  
  25668.  
  25669.  
  25670.  
  25671.  
  25672.  4.2 basename - Return nondirectory portion of pathname                359
  25673.  
  25674.  
  25675.  
  25676.  
  25677.  
  25678.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25679.  
  25680.  4.2.5.4  Asynchronous Events
  25681.  
  25682.  Default.
  25683.  
  25684.  
  25685.  4.2.6  External Effects
  25686.  
  25687.  
  25688.  4.2.6.1  Standard Output
  25689.  
  25690.  The basename utility shall write a line to the standard output in the
  25691.  following format:
  25692.  
  25693.        "%s\n", <_r_e_s_u_l_t_i_n_g _s_t_r_i_n_g>
  25694.  
  25695.  4.2.6.2  Standard Error
  25696.  
  25697.  Used only for diagnostic messages.
  25698.  
  25699.  
  25700.  4.2.6.3  Output Files
  25701.  
  25702.  None.
  25703.  
  25704.  
  25705.  4.2.7  Extended Description
  25706.  
  25707.  None.
  25708.  
  25709.  
  25710.  4.2.8  Exit Status
  25711.  
  25712.  The basename utility shall exit with one of the following values:
  25713.  
  25714.      0    Successful completion.
  25715.  
  25716.     >0    An error occurred.
  25717.  
  25718.  
  25719.  4.2.9  Consequences of Errors
  25720.  
  25721.  Default.
  25722.  
  25723.  BEGIN_RATIONALE
  25724.  
  25725.  
  25726.  
  25727.  
  25728.  
  25729.  
  25730.  
  25731.                Copyright c 1991 IEEE.  All rights reserved.
  25732.       This is an unapproved IEEE Standards Draft, subject to change.
  25733.  
  25734.  
  25735.  
  25736.  
  25737.  
  25738.  360                                     4 Execution Environment Utilities
  25739.  
  25740.  
  25741.  
  25742.  
  25743.  
  25744.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25745.  
  25746.  4.2.10  Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  25747.  
  25748.  _E_x_a_m_p_l_e_s_,__U_s_a_g_e
  25749.  
  25750.  If the string _s_t_r_i_n_g is a valid pathname,
  25751.  
  25752.        $(basename "string")
  25753.  
  25754.  produces a filename that could be used to open the file named by _s_t_r_i_n_g
  25755.  in the directory returned by
  25756.  
  25757.        $(dirname "string")
  25758.  
  25759.  If the string _s_t_r_i_n_g is not a valid pathname, the same algorithm is used,
  25760.  but the result need not be a valid filename.  The basename utility is not
  25761.  expected to make any judgements about the validity of _s_t_r_i_n_g as a
  25762.  pathname; it just follows the specified algorithm to produce a result
  25763.  string.
  25764.  
  25765.  The following shell script compiles /usr/src/cmd/cat.c and moves the
  25766.  output to a file named cat in the current directory when invoked with the
  25767.  argument /usr/src/cmd/cat or with the argument /usr/src/cmd/cat.c:
  25768.  
  25769.        c89 $(dirname "$1")/$(basename "$1" .c).c
  25770.        mv a.out $(basename "$1" .c)
  25771.  
  25772.  _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e
  25773.  
  25774.  The POSIX.1 {8} definition of pathname allows trailing slashes on a
  25775.  pathname naming a directory.  Some historical implementations have not
  25776.  allowed trailing slashes and thus treated pathnames of this form in other
  25777.  ways.  Existing implementations also differ in their handling of _s_u_f_f_i_x
  25778.  when _s_u_f_f_i_x matches the entire string left after removing the directory
  25779.  part of _s_t_r_i_n_g.
  25780.  
  25781.  The behaviors of basename and dirname in this standard have been
  25782.  coordinated so that when _s_t_r_i_n_g is a valid pathname
  25783.  
  25784.        $(basename "string")
  25785.  
  25786.  would be a valid filename for the file in the directory
  25787.  
  25788.        $(dirname "string")
  25789.  
  25790.  This would not work for the versions of these utilities in earlier drafts
  25791.  due to the way it specified handling of trailing slashes.
  25792.  
  25793.  Since the definition of _p_a_t_h_n_a_m_e in 2.2.2.102 specifies implementation-
  25794.  defined behavior for pathnames starting with two slash characters, Draft
  25795.  
  25796.  
  25797.                Copyright c 1991 IEEE.  All rights reserved.
  25798.       This is an unapproved IEEE Standards Draft, subject to change.
  25799.  
  25800.  
  25801.  
  25802.  
  25803.  
  25804.  4.2 basename - Return nondirectory portion of pathname                361
  25805.  
  25806.  
  25807.  
  25808.  
  25809.  
  25810.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25811.  
  25812.  11 has been changed to specify similar implementation-defined behavior
  25813.  for the basename and dirname utilities.  On implementations where the
  25814.  pathname // is always treated the same as the pathname /, the
  25815.  functionality required by Draft 10 meets all of the Draft 11
  25816.  requirements.
  25817.  
  25818.  END_RATIONALE
  25819.  
  25820.  
  25821.  
  25822.  4.3  bc - Arbitrary-precision arithmetic language
  25823.  
  25824.  
  25825.  4.3.1  Synopsis
  25826.  
  25827.  bc  [-l] [_f_i_l_e ...]
  25828.  
  25829.  
  25830.  4.3.2  Description
  25831.  
  25832.  The bc utility shall implement an arbitrary precision calculator.  It
  25833.  shall take input from any files given, then read from the standard input.
  25834.  If the standard input and standard output to bc are attached to a
  25835.  terminal, the invocation of bc shall be considered to be _i_n_t_e_r_a_c_t_i_v_e,
  25836.  causing behavioral constraints described in the following subclauses.
  25837.  
  25838.  
  25839.  4.3.3  Options
  25840.  
  25841.  The bc utility shall conform to the utility argument syntax guidelines
  25842.  described in 2.10.2.
  25843.  
  25844.  The following option shall be supported by the implementation:
  25845.  
  25846.     -l          (The letter ell.)  Define the math functions and
  25847.                 initialize scale to 20, instead of the default zero.  See
  25848.                 4.3.7.
  25849.  
  25850.  
  25851.  4.3.4  Operands
  25852.  
  25853.  The following operands shall be supported by the implementation:
  25854.  
  25855.     _f_i_l_e        A pathname of a text file containing bc program
  25856.                 statements.  After all _f_i_l_es have been read, bc shall read
  25857.                 the standard input.
  25858.  
  25859.  
  25860.  
  25861.  
  25862.  
  25863.                Copyright c 1991 IEEE.  All rights reserved.
  25864.       This is an unapproved IEEE Standards Draft, subject to change.
  25865.  
  25866.  
  25867.  
  25868.  
  25869.  
  25870.  362                                     4 Execution Environment Utilities
  25871.  
  25872.  
  25873.  
  25874.  
  25875.  
  25876.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  25877.  
  25878.  4.3.5  External Influences
  25879.  
  25880.  
  25881.  4.3.5.1  Standard Input
  25882.  
  25883.  See Input Files.
  25884.  
  25885.  4.3.5.2  Input Files
  25886.  
  25887.  Input files shall be text files containing a sequence of comments,
  25888.  statements, and function definitions that shall be executed as they are
  25889.  read.
  25890.  
  25891.  
  25892.  4.3.5.3  Environment Variables
  25893.  
  25894.  The following environment variables shall affect the execution of bc:
  25895.  
  25896.     LANG               This variable shall determine the locale to use for
  25897.                        the locale categories when both LC_ALL and the
  25898.                        corresponding environment variable (beginning with
  25899.                        LC_) do not specify a locale.  See 2.6.
  25900.  
  25901.     LC_ALL             This variable shall determine the locale to be used
  25902.                        to override any values for locale categories
  25903.                        specified by the settings of LANG or any
  25904.                        environment variables beginning with LC_.
  25905.  
  25906.     LC_CTYPE           This variable shall determine the locale for the
  25907.                        interpretation of sequences of bytes of text data
  25908.                        as characters (e.g., single- versus multibyte
  25909.                        characters in arguments and input files).
  25910.  
  25911.     LC_MESSAGES        This variable shall determine the language in which
  25912.                        messages should be written.
  25913.  
  25914.  4.3.5.4  Asynchronous Events
  25915.  
  25916.  Default.
  25917.  
  25918.  
  25919.  4.3.6  External Effects
  25920.  
  25921.  
  25922.  
  25923.  
  25924.  
  25925.  
  25926.  
  25927.  
  25928.  
  25929.                Copyright c 1991 IEEE.  All rights reserved.
  25930.       This is an unapproved IEEE Standards Draft, subject to change.
  25931.  
  25932.  
  25933.  
  25934.  
  25935.  
  25936.  4.3 bc - Arbitrary-precision arithmetic language                      363
  25937.  
  25938.  
  25939.  
  25940.  
  25941.  
  25942.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  25943.  
  25944.  4.3.6.1  Standard Output
  25945.  
  25946.  The output of the bc utility shall be controlled by the program read, and
  25947.  shall consist of zero or more lines containing the value of all executed   2
  25948.  expressions without assignments.  The radix and precision of the output    2
  25949.  shall be controlled by the values of the obase and scale variables.  See
  25950.  4.3.7.
  25951.  
  25952.  
  25953.  4.3.6.2  Standard Error
  25954.  
  25955.  Used only for diagnostic messages.
  25956.  
  25957.  4.3.6.3  Output Files
  25958.  
  25959.  None.
  25960.  
  25961.  
  25962.  4.3.7  Extended Description
  25963.  
  25964.  
  25965.  4.3.7.1  bc Grammar
  25966.  
  25967.  The grammar in this subclause and the lexical conventions in the
  25968.  following subclause shall together describe the syntax for bc programs.
  25969.  The general conventions for this style of grammar are described in 2.1.2.
  25970.  A valid program can be represented as the nonterminal symbol program in
  25971.  the grammar.  Any discrepancies found between this grammar and other
  25972.  descriptions in this subclause (4.3.7) shall be resolved in favor of this
  25973.  grammar.
  25974.  
  25975.  %token   EOF NEWLINE STRING LETTER NUMBER
  25976.  
  25977.  %token   MUL_OP
  25978.  /*       '*', '/', '%'                           */
  25979.  
  25980.  %token   ASSIGN_OP
  25981.  /*       '=', '+=', '-=', '*=', '/=', '%=', '^=' */
  25982.  
  25983.  %token   REL_OP
  25984.  /*       '==', '<=', '>=', '!=', '<', '>'        */
  25985.  
  25986.  %token   INCR_DECR
  25987.  /*       '++', '--'                              */
  25988.  
  25989.  %token    Define    Break    Quit    Length
  25990.  /*       'define', 'break', 'quit', 'length'     */
  25991.  
  25992.  
  25993.  
  25994.  
  25995.                Copyright c 1991 IEEE.  All rights reserved.
  25996.       This is an unapproved IEEE Standards Draft, subject to change.
  25997.  
  25998.  
  25999.  
  26000.  
  26001.  
  26002.  364                                     4 Execution Environment Utilities
  26003.  
  26004.  
  26005.  
  26006.  
  26007.  
  26008.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26009.  
  26010.  %token    Return    For    If    While    Sqrt
  26011.  /*       'return', 'for', 'if', 'while', 'sqrt'  */
  26012.  
  26013.  %token    Scale    Ibase    Obase    Auto
  26014.  /*       'scale', 'ibase', 'obase', 'auto'       */
  26015.  
  26016.  %start   program
  26017.  
  26018.  %%
  26019.  
  26020.  program               : EOF
  26021.                        | input_item program
  26022.                        ;
  26023.  
  26024.  input_item            : semicolon_list NEWLINE
  26025.                        | function
  26026.                        ;
  26027.  
  26028.  semicolon_list        : /* empty */
  26029.                        | statement
  26030.                        | semicolon_list ';' statement
  26031.                        | semicolon_list ';'
  26032.                        ;
  26033.  
  26034.  statement_list        : /* empty */
  26035.                        | statement
  26036.                        | statement_list NEWLINE
  26037.                        | statement_list NEWLINE statement
  26038.                        | statement_list ';'
  26039.                        | statement_list ';' statement
  26040.                        ;
  26041.  
  26042.  statement             : expression
  26043.                        | STRING
  26044.                        | Break
  26045.                        | Quit
  26046.                        | Return
  26047.                        | Return '(' return_expression ')'
  26048.                        | For '(' expression ';'
  26049.                              relational_expression ';'
  26050.                              expression ')' statement
  26051.                        | If '(' relational_expression ')' statement
  26052.                        | While '(' relational_expression ')' statement
  26053.                        | '{' statement_list '}'
  26054.                        ;
  26055.  
  26056.  function              : Define LETTER '(' opt_parameter_list ')'
  26057.  
  26058.  
  26059.  
  26060.  
  26061.                Copyright c 1991 IEEE.  All rights reserved.
  26062.       This is an unapproved IEEE Standards Draft, subject to change.
  26063.  
  26064.  
  26065.  
  26066.  
  26067.  
  26068.  4.3 bc - Arbitrary-precision arithmetic language                      365
  26069.  
  26070.  
  26071.  
  26072.  
  26073.  
  26074.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26075.  
  26076.                              '{' NEWLINE opt_auto_define_list
  26077.                              statement_list '}'
  26078.                        ;
  26079.  
  26080.  opt_parameter_list    : /* empty */
  26081.                        | parameter_list
  26082.                        ;
  26083.  
  26084.  parameter_list        : LETTER
  26085.                        | define_list ',' LETTER
  26086.                        ;
  26087.  
  26088.  opt_auto_define_list  : /* empty */
  26089.                        | Auto define_list NEWLINE
  26090.                        | Auto define_list ';'
  26091.                        ;
  26092.  
  26093.  define_list           : LETTER
  26094.                        | LETTER '[' ']'
  26095.                        | define_list ',' LETTER
  26096.                        | define_list ',' LETTER '[' ']'
  26097.                        ;
  26098.  
  26099.  opt_argument_list     : /* empty */
  26100.                        | argument_list
  26101.                        ;
  26102.  
  26103.  argument_list         : expression
  26104.                        | argument_list ',' expression
  26105.                        ;
  26106.  
  26107.  relational_expression : expression
  26108.                        | expression REL_OP expression
  26109.                        ;
  26110.  
  26111.  return_expression     : /* empty */
  26112.                        | expression
  26113.                        ;
  26114.  
  26115.  expression            : named_expression
  26116.                        | NUMBER
  26117.                        | '(' expression ')'
  26118.                        | LETTER '(' opt_argument_list ')'
  26119.                        | '-' expression
  26120.                        | expression '+' expression                          1
  26121.                        | expression '-' expression                          1
  26122.                        | expression MUL_OP expression
  26123.  
  26124.  
  26125.  
  26126.  
  26127.                Copyright c 1991 IEEE.  All rights reserved.
  26128.       This is an unapproved IEEE Standards Draft, subject to change.
  26129.  
  26130.  
  26131.  
  26132.  
  26133.  
  26134.  366                                     4 Execution Environment Utilities
  26135.  
  26136.  
  26137.  
  26138.  
  26139.  
  26140.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26141.  
  26142.                        | expression '^' expression
  26143.                        | INCR_DECR named_expression
  26144.                        | named_expression INCR_DECR
  26145.                        | named_expression ASSIGN_OP expression
  26146.                        | Length '(' expression ')'
  26147.                        | Sqrt '(' expression ')'
  26148.                        | Scale '(' expression ')'
  26149.                        ;
  26150.  
  26151.  named_expression      : LETTER
  26152.                        | LETTER '[' expression ']'
  26153.                        | Scale
  26154.                        | Ibase
  26155.                        | Obase
  26156.                        ;
  26157.  
  26158.  
  26159.  4.3.7.2  bc Lexical Conventions
  26160.  
  26161.  The lexical conventions for bc programs, with respect to the preceding
  26162.  grammar, shall be as follows:
  26163.  
  26164.      (1)  Except as noted, bc shall recognize the longest possible token
  26165.           or delimiter beginning at a given point.
  26166.  
  26167.      (2)  A comment shall consist of any characters beginning with the two
  26168.           adjacent characters /* and terminated by the next occurrence of
  26169.           the two adjacent characters */.  Comments shall have no effect
  26170.           except to delimit lexical tokens.
  26171.  
  26172.      (3)  The character <newline> shall be recognized as the token
  26173.           NEWLINE.
  26174.  
  26175.      (4)  The token STRING shall represent a string constant; it shall
  26176.           consist of any characters beginning with the double-quote
  26177.           character (") and terminated by another occurrence of the
  26178.           double-quote character.  The value of the string shall be the
  26179.           sequence of all characters between, but not including, the two
  26180.           double-quote characters.  All characters shall be taken
  26181.           literally from the input, and there is no way to specify a
  26182.           string containing a double-quote character.  The length of the
  26183.           value of each string shall be limited to {BC_STRING_MAX} bytes.
  26184.  
  26185.      (5)  A <blank> shall have no effect except as an ordinary character    1
  26186.           if it appears within a STRING token, or to delimit a lexical      1
  26187.           token other than STRING.                                          1
  26188.  
  26189.      (6)  The combination of a backslash character immediately followed by  2
  26190.           a <newline> character shall delimit lexical tokens with the       2
  26191.           following exceptions:                                             2
  26192.  
  26193.                Copyright c 1991 IEEE.  All rights reserved.
  26194.       This is an unapproved IEEE Standards Draft, subject to change.
  26195.  
  26196.  
  26197.  
  26198.  
  26199.  
  26200.  4.3 bc - Arbitrary-precision arithmetic language                      367
  26201.  
  26202.  
  26203.  
  26204.  
  26205.  
  26206.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26207.  
  26208.            - It shall be interpreted as a literal <newline> in STRING       2
  26209.              tokens.                                                        2
  26210.  
  26211.            - It shall be ignored as part of a multiline NUMBER token.       2
  26212.  
  26213.      (7)  The token NUMBER shall represent a numeric constant.  It shall
  26214.           be recognized by the following grammar:
  26215.  
  26216.                 NUMBER  : integer
  26217.                         | '.' integer
  26218.                         | integer '.'
  26219.                         | integer '.' integer
  26220.                         ;
  26221.  
  26222.                 integer : digit
  26223.                         | integer digit
  26224.                         ;
  26225.  
  26226.                 digit   : 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  26227.                         | 8 | 9 | A | B | C | D | E | F
  26228.                         ;
  26229.  
  26230.      (8)  The value of a NUMBER token shall be interpreted as a numeral in
  26231.           the base specified by the value of the internal register ibase
  26232.           (described below).  Each of the digit characters shall have the
  26233.           value from 0 to 15 in the order listed here, and the period
  26234.           character shall represent the radix point.  The behavior is
  26235.           undefined if digits greater than or equal to the value of ibase
  26236.           appear in the token.  (However, note the exception for single-
  26237.           digit values being assigned to ibase and obase themselves, in
  26238.           4.3.7.3).
  26239.  
  26240.      (9)  The following keywords shall be recognized as tokens:
  26241.  
  26242.                       auto     for     length   return   sqrt
  26243.                       break    ibase   obase    scale    while
  26244.                       define   if      quit
  26245.  
  26246.     (10)  Any of the following characters occurring anywhere except within
  26247.           a keyword shall be recognized as the token LETTER:
  26248.  
  26249.                 a b c d e f g h i j k l m n o p q r s t u v w x y z
  26250.  
  26251.     (11)  The following single-character and two-character sequences shall
  26252.           be recognized as the token ASSIGN_OP:
  26253.  
  26254.                 =    +=    -=    *=    /=    %=    ^=
  26255.  
  26256.  
  26257.  
  26258.  
  26259.                Copyright c 1991 IEEE.  All rights reserved.
  26260.       This is an unapproved IEEE Standards Draft, subject to change.
  26261.  
  26262.  
  26263.  
  26264.  
  26265.  
  26266.  368                                     4 Execution Environment Utilities
  26267.  
  26268.  
  26269.  
  26270.  
  26271.  
  26272.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26273.  
  26274.     (12)  If an = character, as the beginning of a token, is followed by a
  26275.           - character with no intervening delimiter, the behavior is
  26276.           undefined.
  26277.  
  26278.     (13)  The following single-characters shall be recognized as the token
  26279.           MUL_OP:
  26280.  
  26281.                 *    /    %
  26282.  
  26283.     (14)  The following single-character and two-character sequences shall
  26284.           be recognized as the token REL_OP:
  26285.  
  26286.                 ==      <=      >=      !=      <      >
  26287.  
  26288.     (15)  The following two-character sequences shall be recognized as the
  26289.           token INCR_DECR:
  26290.  
  26291.                 ++    --
  26292.  
  26293.     (16)  The following single characters shall be recognized as tokens
  26294.           whose names are the character:
  26295.  
  26296.                 <newline>   (   )   ,   +   -   ;   [   ]   ^   {   }       1
  26297.  
  26298.     (17)  The token EOF shall be returned when the end of input is
  26299.           reached.
  26300.  
  26301.  
  26302.  4.3.7.3  bc Operations
  26303.  
  26304.  There are three kinds of identifiers:  ordinary identifiers, array
  26305.  identifiers, and function identifiers.  All three types consist of single
  26306.  lowercase letters.  Array identifiers shall be followed by square
  26307.  brackets ([ ]).  An array subscript is required except in an argument or
  26308.  auto list.  Arrays are singly dimensioned and can contain up to
  26309.  {BC_DIM_MAX} elements.  Indexing begins at zero so an array is indexed
  26310.  from 0 to {BC_DIM_MAX}-1.  Subscripts shall be truncated to integers.
  26311.  Function identifiers shall be followed by parentheses, possibly enclosing
  26312.  arguments.  The three types of identifiers do not conflict.
  26313.  
  26314.  Table 4-3 summarizes the rules for precedence and associativity of all
  26315.  operators.  Operators on the same line shall have the same precedence;
  26316.  rows are in order of decreasing precedence.
  26317.  
  26318.  Each expression or named expression has a _s_c_a_l_e, which is the number of
  26319.  decimal digits that shall be maintained as the fractional portion of the
  26320.  expression.
  26321.  
  26322.  
  26323.  
  26324.  
  26325.                Copyright c 1991 IEEE.  All rights reserved.
  26326.       This is an unapproved IEEE Standards Draft, subject to change.
  26327.  
  26328.  
  26329.  
  26330.  
  26331.  
  26332.  4.3 bc - Arbitrary-precision arithmetic language                      369
  26333.  
  26334.  
  26335.  
  26336.  
  26337.  
  26338.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26339.  
  26340.  
  26341.                         Table 4-3  -  bc Operators
  26342.  __________________________________________________________________________________________________________________________________________________
  26343.                         Operator                     Associativity
  26344.        ____________________________________________________________
  26345.        ++,    --                                     not applicable
  26346.        unary -                                       not applicable
  26347.        ^                                             right to left
  26348.        *,    /,    %                                 left to right
  26349.        +, binary -                                   left to right
  26350.        =,    +=,    -=,    *=,    /=,    %=,    ^=   right to left
  26351.        ==,    <=,    >=,    !=,    <,    >           none
  26352.  __________________________________________________________________________________________________________________________________________________
  26353.  
  26354.  
  26355.  _N_a_m_e_d _e_x_p_r_e_s_s_i_o_n_s are places where values are stored.  Named expressions
  26356.  shall be valid on the left side of an assignment.  The value of a named
  26357.  expression shall be the value stored in the place named.  Simple
  26358.  identifiers and array elements shall be named expressions; they shall
  26359.  have an initial value of zero and an initial scale of zero.
  26360.  
  26361.  The internal registers scale, _i_b_a_s_e, and obase are all named expressions.
  26362.  The scale of an expression consisting of the name of one of these
  26363.  registers shall be zero; values assigned to any of these registers shall
  26364.  be truncated to integers.  The scale register shall contain a global
  26365.  value used in computing the scale of expressions (as described below).
  26366.  The value of the register scale shall be limited to 0 _< scale _<
  26367.  {BC_SCALE_MAX} and shall have a default value of zero.  The ibase and
  26368.  obase registers are the input and output number radix, respectively.  The
  26369.  value of ibase shall be limited to
  26370.  
  26371.        2 _< ibase _< 16
  26372.  
  26373.  The value of obase shall be limited to
  26374.  
  26375.        2 _< obase _< {BC_BASE_MAX}
  26376.  
  26377.  When either ibase or obase is assigned a single digit value from the list
  26378.  in 4.3.7.2, the value shall be assumed in hexadecimal.  (For example,
  26379.  ibase=A sets to base ten, regardless of the current ibase value.)
  26380.  Otherwise, the behavior is undefined when digits greater than or equal to
  26381.  the value of ibase appear in the input.  Both ibase and obase shall have
  26382.  initial values of 10.
  26383.  
  26384.  Internal computations shall be conducted as if in decimal, regardless of   1
  26385.  the input and output bases, to the specified number of decimal digits.
  26386.  When an exact result is not achieved, (e.g., scale=0; 3.2/1) the result
  26387.  shall be truncated.
  26388.  
  26389.  
  26390.  
  26391.                Copyright c 1991 IEEE.  All rights reserved.
  26392.       This is an unapproved IEEE Standards Draft, subject to change.
  26393.  
  26394.  
  26395.  
  26396.  
  26397.  
  26398.  370                                     4 Execution Environment Utilities
  26399.  
  26400.  
  26401.  
  26402.  
  26403.  
  26404.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26405.  
  26406.  For all values of obase specified by this standard, numerical values
  26407.  shall be output as follows:
  26408.  
  26409.      (1)  If the value is less than zero, a hyphen (-) character shall be
  26410.           output.
  26411.  
  26412.      (2)  One of the following shall be output, depending on the numerical
  26413.           value:
  26414.  
  26415.            - If the absolute value of the numerical value is greater than
  26416.              or equal to one, the integer portion of the value shall be
  26417.              output as a series of digits appropriate to obase (as
  26418.              described below).  The most significant nonzero digit shall
  26419.              be output next, followed by each successively less
  26420.              significant digit.
  26421.  
  26422.            - If the absolute value of the numerical value is less than one
  26423.              but greater than zero and the scale of the numerical value is
  26424.              greater than zero, it is unspecified whether the character 0
  26425.              is output.
  26426.  
  26427.            - If the numerical value is zero, the character 0 shall be
  26428.              output.
  26429.  
  26430.      (3)  If the scale of the value is greater than zero, a period
  26431.           character shall be output, followed by a series of digits
  26432.           appropriate to obase (as described below) representing the most
  26433.           significant portion of the fractional part of the value.  If _s
  26434.           represents the scale of the value being output, the number of
  26435.           digits output shall be _s if obase is 10, less than or equal to _s
  26436.           if obase is greater than 10, or greater than or equal to _s if
  26437.           obase is less than 10.  For obase values other than 10, this
  26438.           should be the number of digits needed to represent a precision
  26439.           of 10_s.
  26440.  
  26441.  For obase values from 2 to 16, valid digits are the first obase of the
  26442.  single characters
  26443.  
  26444.        0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
  26445.  
  26446.  which represent the values zero through fifteen, respectively.
  26447.  
  26448.  For bases greater than 16, each ``digit'' shall be written as a separate
  26449.  multidigit decimal number.  Each digit except the most significant
  26450.  fractional digit shall be preceded a single <space> character.  For bases
  26451.  from 17 to 100, bc shall write two-digit decimal numbers; for bases from
  26452.  101 to 999, three-digit decimal strings, and so on.  For example, the
  26453.  decimal number 1024 in base 25 would be written as:
  26454.  
  26455.  
  26456.  
  26457.                Copyright c 1991 IEEE.  All rights reserved.
  26458.       This is an unapproved IEEE Standards Draft, subject to change.
  26459.  
  26460.  
  26461.  
  26462.  
  26463.  
  26464.  4.3 bc - Arbitrary-precision arithmetic language                      371
  26465.  
  26466.  
  26467.  
  26468.  
  26469.  
  26470.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26471.  
  26472.        W01W15W24
  26473.  
  26474.  in base 125, as:
  26475.  
  26476.        W008W024
  26477.  
  26478.  Very large numbers shall be split across lines with 70 characters per
  26479.  line in the POSIX Locale; other locales may split at different character
  26480.  boundaries.  Lines that are continued shall end with a backslash (\).
  26481.  
  26482.  A function call shall consist of a function name followed by parentheses
  26483.  containing a comma-separated list of expressions, which are the function
  26484.  arguments.  A whole array passed as an argument shall be specified by the
  26485.  array name followed by empty square brackets.  All function arguments
  26486.  shall be passed by value.  As a result, changes made to the formal
  26487.  parameters have no effect on the actual arguments.  If the function
  26488.  terminates by executing a return statement, the value of the function
  26489.  shall be the value of the expression in the parentheses of the return
  26490.  statement or shall be zero if no expression is provided or if there is no
  26491.  return statement.
  26492.  
  26493.  The result of sqrt(_e_x_p_r_e_s_s_i_o_n) _s_h_a_l_l _b_e _t_h_e _s_q_u_a_r_e _r_o_o_t _o_f _t_h_e
  26494.  _e_x_p_r_e_s_s_i_o_n.  _T_h_e _r_e_s_u_l_t _s_h_a_l_l _b_e _t_r_u_n_c_a_t_e_d _i_n _t_h_e _l_e_a_s_t _s_i_g_n_i_f_i_c_a_n_t
  26495.  _d_e_c_i_m_a_l _p_l_a_c_e.  _T_h_e _s_c_a_l_e _o_f _t_h_e _r_e_s_u_l_t _s_h_a_l_l _b_e _t_h_e _s_c_a_l_e _o_f _t_h_e
  26496.  _e_x_p_r_e_s_s_i_o_n _o_r _t_h_e _v_a_l_u_e _o_f _s_c_a_l_e, whichever is larger.
  26497.  
  26498.  The result of length(_e_x_p_r_e_s_s_i_o_n) _s_h_a_l_l _b_e _t_h_e _t_o_t_a_l _n_u_m_b_e_r _o_f _s_i_g_n_i_f_i_c_a_n_t
  26499.  _d_e_c_i_m_a_l _d_i_g_i_t_s _i_n _t_h_e _e_x_p_r_e_s_s_i_o_n.  _T_h_e _s_c_a_l_e _o_f _t_h_e _r_e_s_u_l_t _s_h_a_l_l _b_e _z_e_r_o.
  26500.  
  26501.  _T_h_e _r_e_s_u_l_t _o_f _s_c_a_l_e(_e_x_p_r_e_s_s_i_o_n) _s_h_a_l_l _b_e _t_h_e _s_c_a_l_e _o_f _t_h_e _e_x_p_r_e_s_s_i_o_n.
  26502.  _T_h_e _s_c_a_l_e _o_f _t_h_e _r_e_s_u_l_t _s_h_a_l_l _b_e _z_e_r_o.
  26503.  
  26504.  _A _n_u_m_e_r_i_c _c_o_n_s_t_a_n_t _s_h_a_l_l _b_e _a_n _e_x_p_r_e_s_s_i_o_n.  _T_h_e _s_c_a_l_e _s_h_a_l_l _b_e _t_h_e _n_u_m_b_e_r
  26505.  _o_f _d_i_g_i_t_s _t_h_a_t _f_o_l_l_o_w _t_h_e _r_a_d_i_x _p_o_i_n_t _i_n _t_h_e _i_n_p_u_t _r_e_p_r_e_s_e_n_t_i_n_g _t_h_e
  26506.  _c_o_n_s_t_a_n_t, _o_r _z_e_r_o _i_f _n_o _r_a_d_i_x _p_o_i_n_t _a_p_p_e_a_r_s.
  26507.  
  26508.  _T_h_e _s_e_q_u_e_n_c_e ( _e_x_p_r_e_s_s_i_o_n ) _s_h_a_l_l _b_e _a_n _e_x_p_r_e_s_s_i_o_n _w_i_t_h _t_h_e _s_a_m_e _v_a_l_u_e
  26509.  _a_n_d _s_c_a_l_e _a_s _e_x_p_r_e_s_s_i_o_n. The parentheses can be used to alter the normal
  26510.  precedence.
  26511.  
  26512.  The semantics of the unary and binary operators are as follows.
  26513.  
  26514.     -_e_x_p_r_e_s_s_i_o_n
  26515.              The result shall be the negative of the _e_x_p_r_e_s_s_i_o_n.  The
  26516.              scale of the result shall be the scale of _e_x_p_r_e_s_s_i_o_n.
  26517.  
  26518.  The unary increment and decrement operators shall not modify the scale of
  26519.  the named expression upon which they operate.  The scale of the result
  26520.  shall be the scale of that named expression.
  26521.  
  26522.  
  26523.                Copyright c 1991 IEEE.  All rights reserved.
  26524.       This is an unapproved IEEE Standards Draft, subject to change.
  26525.  
  26526.  
  26527.  
  26528.  
  26529.  
  26530.  372                                     4 Execution Environment Utilities
  26531.  
  26532.  
  26533.  
  26534.  
  26535.  
  26536.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26537.  
  26538.     ++_n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n
  26539.              The named expression shall be incremented by one.  The result
  26540.              shall be the value of the named expression after
  26541.              incrementing.
  26542.  
  26543.     --_n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n
  26544.              The named expression shall be decremented by one.  The result
  26545.              shall be the value of the named expression after
  26546.              decrementing.
  26547.  
  26548.     _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n++
  26549.              The named expression shall be incremented by one.  The result
  26550.              shall be the value of the named expression before
  26551.              incrementing.
  26552.  
  26553.     _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n--
  26554.              The named expression shall be decremented by one.  The result
  26555.              shall be the value of the named expression before
  26556.              decrementing.
  26557.  
  26558.  The exponentiation operator, circumflex (^), shall bind right to left.
  26559.  
  26560.     _e_x_p_r_e_s_s_i_o_n^_e_x_p_r_e_s_s_i_o_n
  26561.              The result shall be the first _e_x_p_r_e_s_s_i_o_n raised to the power
  26562.              of the second _e_x_p_r_e_s_s_i_o_n.  If the second expression is not an
  26563.              integer, the behavior is undefined.  If a is the scale of the
  26564.              left expression and b is the absolute value of the right
  26565.              expression, the scale of the result shall be:
  26566.  
  26567.                    if b >= 0 min(a * b, max(scale, a))                      2
  26568.                    if b <  0 scale                                          2
  26569.  
  26570.  The multiplicative operators (*, /, %) shall bind left to right.
  26571.  
  26572.     _e_x_p_r_e_s_s_i_o_n * _e_x_p_r_e_s_s_i_o_n
  26573.              The result shall be the product of the two expressions.  If a
  26574.              and b are the scales of the two expressions, then the scale
  26575.              of the result shall be:
  26576.  
  26577.                    min(a+b,max(scale,a,b))
  26578.  
  26579.     _e_x_p_r_e_s_s_i_o_n / _e_x_p_r_e_s_s_i_o_n
  26580.              The result shall be the quotient of the two expressions.  The
  26581.              scale of the result shall be the value of scale.
  26582.  
  26583.     _e_x_p_r_e_s_s_i_o_n % _e_x_p_r_e_s_s_i_o_n
  26584.              _F_o_r _e_x_p_r_e_s_s_i_o_n_s _a and _b, a % b shall be evaluated equivalent
  26585.              to the steps:
  26586.  
  26587.  
  26588.  
  26589.                Copyright c 1991 IEEE.  All rights reserved.
  26590.       This is an unapproved IEEE Standards Draft, subject to change.
  26591.  
  26592.  
  26593.  
  26594.  
  26595.  
  26596.  4.3 bc - Arbitrary-precision arithmetic language                      373
  26597.  
  26598.  
  26599.  
  26600.  
  26601.  
  26602.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26603.  
  26604.               (1)  Compute a/b to current scale.
  26605.  
  26606.               (2)  Use the result to compute
  26607.  
  26608.                          a - (a / b) * b
  26609.  
  26610.                    to scale
  26611.  
  26612.                          max(scale + scale(b), scale(a))
  26613.  
  26614.              The scale of the result shall be
  26615.  
  26616.                    max(scale + scale(b), scale(a))
  26617.  
  26618.  The additive operators (+, -) shall bind left to right.
  26619.  
  26620.     _e_x_p_r_e_s_s_i_o_n + _e_x_p_r_e_s_s_i_o_n
  26621.              The result shall be the sum of the two expressions.  The
  26622.              scale of the result shall be the maximum of the scales of the
  26623.              expressions.
  26624.  
  26625.     _e_x_p_r_e_s_s_i_o_n - _e_x_p_r_e_s_s_i_o_n
  26626.              The result shall be the difference of the two expressions.
  26627.              The scale of the result shall be the maximum of the scales of
  26628.              the expressions.
  26629.  
  26630.  The assignment operators (=, +=, -=, *=, /=, %=, ^=) shall bind right to
  26631.  left.
  26632.  
  26633.     _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n = _e_x_p_r_e_s_s_i_o_n
  26634.              This expression results in assigning the value of the
  26635.              expression on the right to the named expression on the left.
  26636.              The scale of both the named expression and the result shall
  26637.              be the scale of _e_x_p_r_e_s_s_i_o_n.
  26638.  
  26639.  The compound assignments forms
  26640.  
  26641.        _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n <_o_p_e_r_a_t_o_r>= _e_x_p_r_e_s_s_i_o_n
  26642.  
  26643.  shall be equivalent to:
  26644.  
  26645.        _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n = _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n <_o_p_e_r_a_t_o_r> _e_x_p_r_e_s_s_i_o_n
  26646.  
  26647.  except that the _n_a_m_e_d-_e_x_p_r_e_s_s_i_o_n shall be evaluated only once.
  26648.  
  26649.  Unlike all other operators, the relational operators (<, >, <=, >=, ==,
  26650.  !=) shall be only valid as the object of an if, while, or inside a for
  26651.  statement.
  26652.  
  26653.  
  26654.  
  26655.                Copyright c 1991 IEEE.  All rights reserved.
  26656.       This is an unapproved IEEE Standards Draft, subject to change.
  26657.  
  26658.  
  26659.  
  26660.  
  26661.  
  26662.  374                                     4 Execution Environment Utilities
  26663.  
  26664.  
  26665.  
  26666.  
  26667.  
  26668.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26669.  
  26670.     _e_x_p_r_e_s_s_i_o_n_1 < _e_x_p_r_e_s_s_i_o_n_2
  26671.              The relation shall be true if the value of _e_x_p_r_e_s_s_i_o_n_1 is
  26672.              strictly less than the value of _e_x_p_r_e_s_s_i_o_n_2.
  26673.  
  26674.     _e_x_p_r_e_s_s_i_o_n_1 > _e_x_p_r_e_s_s_i_o_n_2
  26675.              The relation shall be true if the value of _e_x_p_r_e_s_s_i_o_n_1 is
  26676.              strictly greater than the value of _e_x_p_r_e_s_s_i_o_n_2.
  26677.  
  26678.     _e_x_p_r_e_s_s_i_o_n_1 <= _e_x_p_r_e_s_s_i_o_n_2
  26679.              The relation shall be true if the value of _e_x_p_r_e_s_s_i_o_n_1 is
  26680.              less than or equal to the value of _e_x_p_r_e_s_s_i_o_n_2.
  26681.  
  26682.     _e_x_p_r_e_s_s_i_o_n_1 >= _e_x_p_r_e_s_s_i_o_n_2
  26683.              The relation shall be true if the value of _e_x_p_r_e_s_s_i_o_n_1 is
  26684.              greater than or equal to the value of _e_x_p_r_e_s_s_i_o_n_2.
  26685.  
  26686.     _e_x_p_r_e_s_s_i_o_n_1 == _e_x_p_r_e_s_s_i_o_n_2
  26687.              The relation shall be true if the values of _e_x_p_r_e_s_s_i_o_n_1 and
  26688.              _e_x_p_r_e_s_s_i_o_n_2 are equal.
  26689.  
  26690.     _e_x_p_r_e_s_s_i_o_n_1 != _e_x_p_r_e_s_s_i_o_n_2
  26691.              The relation shall be true if the values of _e_x_p_r_e_s_s_i_o_n_1 and
  26692.              _e_x_p_r_e_s_s_i_o_n_2 are unequal.
  26693.  
  26694.  There are only two storage classes in bc, global and automatic (local).
  26695.  Only identifiers that are to be local to a function need be declared with
  26696.  the auto command.  The arguments to a function shall be local to the
  26697.  function.  All other identifiers are assumed to be global and available
  26698.  to all functions.  All identifiers, global and local, have initial values
  26699.  of zero.  Identifiers declared as auto shall be allocated on entry to the
  26700.  function and released on returning from the function.  They therefore do
  26701.  not retain values between function calls.  Auto arrays shall be specified
  26702.  by the array name followed by empty square brackets.  On entry to a
  26703.  function, the old values of the names that appear as parameters and as
  26704.  automatic variables are pushed onto a stack.  Until return is made from
  26705.  the function, reference to these names refers only to the new values.
  26706.  
  26707.  References to any of these names from other functions that are called
  26708.  from this function also refer to the new value until one of those
  26709.  functions uses the same name for a local variable.
  26710.  
  26711.  When a statement is an expression, unless the main operator is an
  26712.  assignment, execution of the statement shall write the value of the
  26713.  expression followed by a <newline> character.
  26714.  
  26715.  When a statement is a string, execution of the statement shall write the
  26716.  value of the string.
  26717.  
  26718.  
  26719.  
  26720.  
  26721.                Copyright c 1991 IEEE.  All rights reserved.
  26722.       This is an unapproved IEEE Standards Draft, subject to change.
  26723.  
  26724.  
  26725.  
  26726.  
  26727.  
  26728.  4.3 bc - Arbitrary-precision arithmetic language                      375
  26729.  
  26730.  
  26731.  
  26732.  
  26733.  
  26734.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26735.  
  26736.  Statements separated by semicolon or <newline> shall be executed
  26737.  sequentially.  In an interactive invocation of bc, each time a <newline>
  26738.  character is read that satisfies the grammatical production
  26739.  
  26740.        input_item : semicolon_list NEWLINE
  26741.  
  26742.  the sequential list of statements making up the semicolon_list shall be
  26743.  executed immediately and any output produced by that execution shall be
  26744.  written without any delay due to buffering.
  26745.  
  26746.  In an if statement [if (_r_e_l_a_t_i_o_n) _s_t_a_t_e_m_e_n_t] the _s_t_a_t_e_m_e_n_t shall be
  26747.  executed if the relation is true.
  26748.  
  26749.  The while statement [while (_r_e_l_a_t_i_o_n) _s_t_a_t_e_m_e_n_t] implements a loop in
  26750.  which the _r_e_l_a_t_i_o_n is tested; each time the _r_e_l_a_t_i_o_n is true, the
  26751.  _s_t_a_t_e_m_e_n_t shall be executed and the _r_e_l_a_t_i_o_n retested.  When the _r_e_l_a_t_i_o_n
  26752.  is false, execution shall resume after _s_t_a_t_e_m_e_n_t.
  26753.  
  26754.  A for statement [for (_e_x_p_r_e_s_s_i_o_n; _r_e_l_a_t_i_o_n; _e_x_p_r_e_s_s_i_o_n) _s_t_a_t_e_m_e_n_t] shall
  26755.  be the same as:
  26756.  
  26757.        _f_i_r_s_t-_e_x_p_r_e_s_s_i_o_n
  26758.        while (_r_e_l_a_t_i_o_n) {
  26759.                _s_t_a_t_e_m_e_n_t
  26760.                _l_a_s_t-_e_x_p_r_e_s_s_i_o_n
  26761.        }
  26762.  
  26763.  All three expressions shall be present.
  26764.  
  26765.  The break statement causes termination of a for or while statement.
  26766.  
  26767.  The auto statement [auto _i_d_e_n_t_i_f_i_e_r[,_i_d_e_n_t_i_f_i_e_r] ...]  _s_h_a_l_l _c_a_u_s_e _t_h_e
  26768.  _v_a_l_u_e_s _o_f _t_h_e _i_d_e_n_t_i_f_i_e_r_s _t_o _b_e _p_u_s_h_e_d _d_o_w_n.  _T_h_e _i_d_e_n_t_i_f_i_e_r_s _c_a_n _b_e
  26769.  _o_r_d_i_n_a_r_y _i_d_e_n_t_i_f_i_e_r_s _o_r _a_r_r_a_y _i_d_e_n_t_i_f_i_e_r_s.  _A_r_r_a_y _i_d_e_n_t_i_f_i_e_r_s _s_h_a_l_l _b_e
  26770.  _s_p_e_c_i_f_i_e_d _b_y _f_o_l_l_o_w_i_n_g _t_h_e _a_r_r_a_y _n_a_m_e _b_y _e_m_p_t_y _s_q_u_a_r_e _b_r_a_c_k_e_t_s.  _T_h_e _a_u_t_o
  26771.  statement shall be the first statement in a function definition.
  26772.  
  26773.  A define statement:
  26774.  
  26775.        define _L_E_T_T_E_R ( _o_p_t__p_a_r_a_m_e_t_e_r__l_i_s_t ) {
  26776.                _o_p_t__a_u_t_o__d_e_f_i_n_e__l_i_s_t
  26777.                _s_t_a_t_e_m_e_n_t__l_i_s_t
  26778.        }
  26779.  
  26780.  defines a function named _L_E_T_T_E_R. If a function named _L_E_T_T_E_R was
  26781.  previously defined, the define statement shall replace the previous
  26782.  definition.  The expression
  26783.  
  26784.  
  26785.  
  26786.  
  26787.                Copyright c 1991 IEEE.  All rights reserved.
  26788.       This is an unapproved IEEE Standards Draft, subject to change.
  26789.  
  26790.  
  26791.  
  26792.  
  26793.  
  26794.  376                                     4 Execution Environment Utilities
  26795.  
  26796.  
  26797.  
  26798.  
  26799.  
  26800.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26801.  
  26802.        _L_E_T_T_E_R ( _o_p_t__a_r_g_u_m_e_n_t__l_i_s_t )
  26803.  
  26804.  shall invoke the function named _L_E_T_T_E_R. The behavior is undefined if the
  26805.  number of arguments in the invocation does not match the number of
  26806.  parameters in the definition.  Functions shall be defined before they are
  26807.  invoked.  A function shall be considered to be defined within its own
  26808.  body, so recursive calls shall be valid.  The values of numeric constants
  26809.  within a function shall be interpreted in the base specified by the value
  26810.  of the ibase register when the function is invoked.
  26811.  
  26812.  The return statements [return and return(_e_x_p_r_e_s_s_i_o_n)] shall cause
  26813.  termination of a function, popping of its auto variables, and specifies
  26814.  the result of the function.  The first form shall be equivalent to
  26815.  return(0).  The value and scale of an invocation of the function shall be
  26816.  the value and scale of the expression in parentheses.
  26817.  
  26818.  The quit statement (quit) _s_h_a_l_l _s_t_o_p _e_x_e_c_u_t_i_o_n _o_f _a _b_c program at the
  26819.  point where the statement occurs in the input, even if it occurs in a
  26820.  function definition, or in an if, for, or while statement.
  26821.  
  26822.  The following functions shall be defined when the -l option is specified:
  26823.  
  26824.     s ( _E_x_p_r_e_s_s_i_o_n )     Sine of argument in radians
  26825.  
  26826.     c ( _E_x_p_r_e_s_s_i_o_n )     _C_o_s_i_n_e _o_f _a_r_g_u_m_e_n_t _i_n _r_a_d_i_a_n_s
  26827.  
  26828.     _a ( _E_x_p_r_e_s_s_i_o_n )     _A_r_c_t_a_n_g_e_n_t _o_f _a_r_g_u_m_e_n_t
  26829.  
  26830.     _l ( _E_x_p_r_e_s_s_i_o_n )     _N_a_t_u_r_a_l _l_o_g_a_r_i_t_h_m _o_f _a_r_g_u_m_e_n_t
  26831.  
  26832.     _e ( _E_x_p_r_e_s_s_i_o_n )     _E_x_p_o_n_e_n_t_i_a_l _f_u_n_c_t_i_o_n _o_f _a_r_g_u_m_e_n_t
  26833.  
  26834.     _j ( _E_x_p_r_e_s_s_i_o_n , _E_x_p_r_e_s_s_i_o_n )
  26835.                          _B_e_s_s_e_l _f_u_n_c_t_i_o_n _o_f _i_n_t_e_g_e_r _o_r_d_e_r
  26836.  
  26837.  _T_h_e _s_c_a_l_e _o_f _a_n _i_n_v_o_c_a_t_i_o_n _o_f _e_a_c_h _o_f _t_h_e_s_e _f_u_n_c_t_i_o_n_s _s_h_a_l_l _b_e _t_h_e _v_a_l_u_e
  26838.  _o_f _t_h_e _s_c_a_l_e register when the function is invoked.  The behavior is
  26839.  undefined if any of these functions is invoked with an argument outside
  26840.  the domain of the mathematical function.
  26841.  
  26842.  
  26843.  4.3.8  Exit Status
  26844.  
  26845.  The bc utility shall exit with one of the following values:
  26846.  
  26847.     0              All input files were processed successfully.
  26848.  
  26849.  
  26850.  
  26851.  
  26852.  
  26853.                Copyright c 1991 IEEE.  All rights reserved.
  26854.       This is an unapproved IEEE Standards Draft, subject to change.
  26855.  
  26856.  
  26857.  
  26858.  
  26859.  
  26860.  4.3 bc - Arbitrary-precision arithmetic language                      377
  26861.  
  26862.  
  26863.  
  26864.  
  26865.  
  26866.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26867.  
  26868.     _u_n_s_p_e_c_i_f_i_e_d    An error occurred.
  26869.  
  26870.  
  26871.  4.3.9  Consequences of Errors
  26872.  
  26873.  If any _f_i_l_e operand is specified and the named file cannot be accessed,
  26874.  bc shall write a diagnostic message to standard error and terminate
  26875.  without any further action.
  26876.  
  26877.  In an interactive invocation of bc, the utility should print an error
  26878.  message and recover following any error in the input.  In a
  26879.  noninteractive invocation of bc, invalid input causes undefined behavior.
  26880.  
  26881.  BEGIN_RATIONALE
  26882.  
  26883.  
  26884.  4.3.10  Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2)
  26885.  
  26886.  _E_x_a_m_p_l_e_s_,__U_s_a_g_e
  26887.  
  26888.  This description is based on _B_C--_A_n _A_r_b_i_t_r_a_r_y _P_r_e_c_i_s_i_o_n _D_e_s_k-_C_a_l_c_u_l_a_t_o_r
  26889.  _L_a_n_g_u_a_g_e by Lorinda Cherry and Robert Morris, in the BSD User Manual
  26890.  {B28}.
  26891.  
  26892.  Automatic variables in bc do not work in exactly the same way as in
  26893.  either C or PL/1.
  26894.  
  26895.  In the shell, the following assigns an approximation of the first ten
  26896.  digits of J to the variable _x:
  26897.  
  26898.        x=$(printf "%s\n" 'scale = 10; 104348/33215' | bc)
  26899.  
  26900.  The following bc program prints the same approximation of J, with a
  26901.  label, to standard output:
  26902.  
  26903.        scale = 10
  26904.        "pi equals "
  26905.        104348 / 33215
  26906.  
  26907.  The following defines a function to compute an approximate value of the
  26908.  exponential function (note that such a function is predefined if the -l
  26909.  option is specified):
  26910.  
  26911.  
  26912.  
  26913.  
  26914.  
  26915.  
  26916.  
  26917.  
  26918.  
  26919.                Copyright c 1991 IEEE.  All rights reserved.
  26920.       This is an unapproved IEEE Standards Draft, subject to change.
  26921.  
  26922.  
  26923.  
  26924.  
  26925.  
  26926.  378                                     4 Execution Environment Utilities
  26927.  
  26928.  
  26929.  
  26930.  
  26931.  
  26932.  Part 2: SHELL AND UTILITIES                                 P1003.2/D11.2
  26933.  
  26934.        scale = 20
  26935.        define e(x){
  26936.                auto a, b, c, i, s
  26937.                a = 1
  26938.                b = 1
  26939.                s = 1
  26940.                for (i = 1; 1 == 1; i++){
  26941.                        a = a*x
  26942.                        b = b*i
  26943.                        c = a/b
  26944.                        if (c == 0) {
  26945.                                return(s)
  26946.                        }
  26947.                        s = s+c
  26948.                }
  26949.        }
  26950.  
  26951.  The following prints approximate values of the exponential function of
  26952.  the first ten integers:
  26953.  
  26954.        for (i = 1; i <= 10; ++i) {
  26955.                e(i)
  26956.        }
  26957.  
  26958.  _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e
  26959.  
  26960.  The bc utility is traditionally implemented as a front-end processor for
  26961.  dc; dc was not selected to be part of the standard because bc was thought
  26962.  to have a more intuitive programmatic interface.  Current implementations
  26963.  that implement bc using dc are expected to be compliant.
  26964.  
  26965.  The Exit Status for error conditions been left unspecified for several
  26966.  reasons:
  26967.  
  26968.      (1)  The bc utility is used in both interactive and noninteractive
  26969.           situations.  Different exit codes may be appropriate for the two
  26970.           uses.
  26971.  
  26972.      (2)  It is unclear when a nonzero exit should be given; divide-by-
  26973.           zero, undefined functions, and syntax errors are all
  26974.           possibilities.
  26975.  
  26976.      (3)  It is not clear what utility the exit status has.
  26977.  
  26978.      (4)  In the 4.3BSD, System V, and Ninth Edition implementations, bc
  26979.           works in conjunction with dc.  dc is the parent, bc is the
  26980.           child.  This was done to cleanly terminate bc if dc aborted.
  26981.  
  26982.  
  26983.  
  26984.  
  26985.                Copyright c 1991 IEEE.  All rights reserved.
  26986.       This is an unapproved IEEE Standards Draft, subject to change.
  26987.  
  26988.  
  26989.  
  26990.  
  26991.  
  26992.  4.3 bc - Arbitrary-precision arithmetic language                      379
  26993.  
  26994.  
  26995.  
  26996.  
  26997.  
  26998.  P1003.2/D11.2                               INFORMATION TECHNOLOGY--POSIX
  26999.  
  27000.  The decision to have bc exit upon encountering an inaccessible input file
  27001.  is based on the belief that bc _f_i_l_e_1 _f_i_l_e_2 is used most often when at
  27002.  least _f_i_l_e_1 contains data/function declarations/initializations.  Having
  27003.  bc continue with prerequisite files missing is probably not useful.
  27004.  There is no implication in the Consequences of Errors subclause that bc
  27005.  must check all its files for accessibility before opening any of them.
  27006.  
  27007.  There was considerable debate on the appropriateness of the language
  27008.  accepted by bc.  Several members of the balloting group preferred to see
  27009.  either a pure subset of the C language or some changes to make the
  27010.  language more compatible with C.  While the bc language has some obvious
  27011.  similarities to C, it has never claimed to be compatible with any version
  27012.  of C.  An interpreter for a subset of C might be a very worthwhile
  27013.  utility, and it could potentially make bc obsolete.  However, no such
  27014.  utility is known in existing practice, and it was not within the scope of
  27015.  POSIX.2 to define such a language and utility.  If and when they are
  27016.  defined, it may be appropriate to include them in a future revision of
  27017.  this standard.  This left the following alternatives:
  27018.  
  27019.      (1)  Exclude any calculator language from the standard.
  27020.  
  27021.           The consensus of the working group was that a simple
  27022.           programmatic calculator language is very useful.  Also, an
  27023.           interactive version of such a calculator would be very important
  27024.           for the POSIX.2a revision.  The only arguments for excluding any
  27025.           calculator were that it would become obsolete if and when a C-
  27026.           compatible one emerged, or that the absence would encourage the
  27027.           development of such a C-compatible one.  These arguments did not
  27028.           suff